Convert CSV To Wiki Table

This is a method to quickly convert a CSV file to a MediaWiki Table. I created a perl script that does the bulk of the work for you. Just modify your input filehandle and run it. You should have a neat looking table after it's done.

If you want to learn more about editing tables in MediaWiki - check out:

http://www.mediawiki.org/wiki/Help:Tables

The following script assumes you're creating a table out of comma separated values that actually has data in every field. If you have a CSV that has some missing fields you'll have to go back and manually place pipes before the blank entries.


Perl script to convert CSV to MediaWiki table

#!/usr/bin/perl
open(INPUT, "< input.csv")
       or die "Couldn't open file for reading: $!\n";
open(OUTPUT, "> output.txt")
       or die "Couldn't open file for writing: $!\n";   

while (<INPUT>) {
       @fields = split(",");
       printf OUTPUT ("\|$fields[0]\n\|$fields[1]\n\|$fields[2]\n\|$fields[3]\|-\n");
}
close INPUT;
close OUTPUT;