$from = "news.dat.txt"; my %h; open(FILE, "$from") || die "Can't open $from!\n"; while (<FILE>) { chomp; ($title,$url,$site,$date,$description) = split(/~/,$_); # if the date has already been seen, tack this entry on to the hash + value if( $h{$date} ){ $h{$date} .= "|$title~$url~$site~$description"; } # date hasn't been seen, so create a new hash entry else { $h{$date} = "$title~$url~$site~$description"; } } #sort the dates in desc. order foreach $key (sort {$b cmp $a} keys %h) { #do for each item for that date @items = split '\|', $h{$key}; foreach $item (@items) { #split back out the values and print the table my($title,$url,$site,$description) = split /~/,$item; print "<table width=400><tr>"; print "<td><a href=\"$url\"><font color=blue>$title</font></a> +<br><font color=black>$key,$site<br>$description</font></td>"; print "</tr></table><br>"; } }
In reply to Re: Sorting a logfile by date to print to html
by CubicSpline
in thread Sorting a logfile by date to print to html
by PerlGoblin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |