#! c:/perl/bin/perl # # csv2html3.cgi # csvファイルをHTMLのTABLE表示する。 # Convert CSV file to TABLE format of HTML. # # 3.00 : 9/29/06 : Initial revisoin # # $Id: csv2html3.cgi,v 1.1 2006/09/30 05:21:26 Hideki Kanayama Exp $ # Copyright(c) 2005-2006, Hideki Kanayama All rights reserved. # use CGI::Carp qw(fatalsToBrowser); use strict; my $csvfile = "csvfile.csv"; my $backlink = "csv2html3.html"; my $back = "解説ページへ"; my $script = "csv2html3.cgi"; print "Content-Type: text/html\n\n"; my $max = 0; my $row = 0; my @td; my @mat; if (open (CSV, "< $csvfile")) { while (){ my @cols = split(/,/); if ($#cols > $max) { $max = $#cols; } $mat[$row] = \@cols; $td[$row++] = "$_"; } close CSV; } my $query = $ENV{QUERY_STRING}; my ($col1,$sort1) = split /&/, $query; my ($tmp1,$col) = split /=/, $col1; my ($tmp2,$sort) = split /=/, $sort1; my @sortarray; my $i; for ($i=0;$i<=$max;$i++){ if ($col == $i) { $sortarray[$i] = $sort + 1; if ($sortarray[$i] > 2) {$sortarray[$i]=0;} } else { $sortarray[$i] = 1; } } my $topline = shift @td; if ($sort == 1){ @td = sort {(split /,/, $a)[$col] cmp (split /,/, $b)[$col]} @td; } elsif ($sort == 2){ @td= sort {(split /,/, $b)[$col] cmp (split /,/, $a)[$col]} @td; } unshift @td, $topline; print "\n"; print "$back

"; print "\n"; my $colline; $i=0; foreach (@td){ chomp; my @cols = split(/,/); print "\n"; for ($colline=0;$colline<=$max;$colline++){ if ($cols[$colline] eq '') {$cols[$colline] = " "} if ($i==0){ print "\n"; } else { print "\n"; } } print "\n\n"; $i++; } print "
$cols[$colline]$cols[$colline]
\n"; print "\n";