#!c:/perl/bin/perl.exe # #____________________________________________________________________ # # PROJ: csv2htm.pl # DATE: May 1999 # $ver = "0.9"; # # # http://www.blazonry.com/perl/csv2htm.php # # DESC: Simple CSV to HTML converter # Converts Comma Delimited text (CSV) to # an HTML file. Used for converting an excel # spreadsheet saved as CSV to an HTML table. # # USAGE: # # csv2htm.pl #____________________________________________________________________ # delimiter # change this to \t for tab delimited, or # any other characters or string for that delimination $delim = ","; printInfo(); $infile = $ARGV[0]; $outfile = $ARGV[1]; if ((!$infile) || (!$outfile)) { printUsage(); } $fstline=1; open (OUT, ">$outfile") || die ("Error Opening $outfile \n$!\n"); printHeader(); open (IN, "<$infile") || die ("Error Opening $infile \n$!\n"); while ($line = ) { chomp($line); if ($fstline) { print OUT ""; $line =~ s/$delim/<\/TH>/g; print OUT "$line"; print OUT "\n"; $fstline = 0; } else { print OUT ""; $line =~ s/$delim/<\/TD>/g; print OUT "$line"; print OUT "\n"; } } close (IN); printFooter(); close(OUT); print "$infile converted to $outfile\n\n"; ##################################################################### ### SUB-ROUTINES # ##################################################################### #____________________________________________________________________ # # SUB: printHeader() # # DESC: prints out HTML header to output file #____________________________________________________________________ sub printHeader { print OUT "\n\n"; print OUT " $infile\n"; print OUT "\n"; print OUT "\n\n\n"; print OUT "\n"; } #____________________________________________________________________ # # SUB: printFooter() # # DESC: prints out HTML Footer to output file #____________________________________________________________________ sub printFooter { print OUT "
\n"; print OUT "\n"; } #____________________________________________________________________ # # SUB: printInfo() # # DESC: prints out script info #____________________________________________________________________ sub printInfo { print "csv2htm.pl ver $ver\n"; print "blazonry.com\n\n"; } #____________________________________________________________________ #____________________________________________________________________ # # SUB: printUsage() # # DESC: prints out script usage #____________________________________________________________________ sub printUsage { print "csv2htm \n"; exit(1); } #____________________________________________________________________