A Perl script to transform CSV fields into HTML rows and cells

#!/usr/bin/perl
# csv4-rows.pl - prepare csv for HTML table
    use strict;
    use warnings;
    use Text::CSV;
    use File::Slurp 'read_file';
    use CGI;
 
my $q = new CGI;
 
#    my $file = 'jp4w4-l.csv';
my $croala = "http://www.ffzg.unizg.hr/klafil/croala/cgi-bin/search3t?dbname=croala&OUTPUT=TF&word=";
my $panon = "http://www.ffzg.unizg.hr/klafil/croala/cgi-bin/search3t?dbname=croala&OUTPUT=TF&author=panonij&word=";
my $file = shift or die 'filename!';
 
my $csv = Text::CSV->new();
open(CSV, '<', $file) or die "Could not open '$file' $!\n";
while (<CSV>) {
    my $broj = $. ;
        if ($csv->parse($_)) {
            my @columns = $csv->fields();
print $q->Tr($q->td([$broj . ".", $columns[0], $columns[1]]), $q->td({align=>"RIGHT"}, $q->b($columns[3])), $q->td(["&nbsp;", $q->a({ href => $panon . $columns[1]}, "Pannonius")]), $q->td({align=>"RIGHT"}, $q->b($columns[5])), $q->td(["&nbsp;", $q->a({ href => $croala . $columns[1]}, "CroALa")])), "\n";
 
        } else {
            my $err = $csv->error_input;
            print "Failed to parse line: $err";
        }
    }
 
z/croala-csv-rows.txt · Last modified: 04. 11. 2012. 18:10 by njovanov
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki