this code can surely be improved (the whole print stuff, %states is not beautiful etc). i just wanted to provide a starting point for you. perl scripts like that (first process data, then print it out) "live" from their datastructure.use strict; use warnings; use diagnostics; my $file = "c:\\test.data"; my ($type, $state); my %data; my %states; open (FH, $file) or die "[$file]:[$!]"; while (<FH>) { ($type, $state) = split (/\|/, $_); if ((defined $type) and (defined $state)) { $type =~ s/^\s*//; $type =~ s/\s*$//; $state =~ s/^\s*//; $state =~ s/\s*$//; $data{$type}->{$state} ++; $states{$state} = 1; } } close (FH); print qq~<table border="1">\n~; print_header (\%states); print_data (\%data, \%states); print "</table>\n"; ############################################################ sub print_data { ############################################################ my ($data_ref, $states_ref) = @_; foreach my $type (keys %$data_ref) { my $total_for_this_type = 0; print "<tr>\n"; print "\t<td>$type</td>\n"; foreach my $state (keys %$states_ref) { $data_ref->{$type}->{$state} or $data_ref->{$type}->{$stat +e} = 0; print "\t<td>", $data_ref->{$type}->{$state}, "</td>\n"; $total_for_this_type += $data_ref->{$type}->{$state}; } print "\t<td>$total_for_this_type</td>\n"; print "</tr>\n"; } } ############################################################ sub print_header { ############################################################ my ($states_ref) = @_; print "<tr>\n"; print "\t<td>MADE</td>\n"; foreach (keys %$states_ref) { print "\t<td>$_</td>\n"; } print "\t<td>TOTAL</td>\n"; print "</tr>\n"; print "<tr>\n"; print "\t<td>====</td>\n"; foreach (keys %$states_ref) { print "\t<td>", "=" x length ($_), "</td>\n"; } print "\t<td>=====</td>\n"; print "</tr>\n"; }
In reply to Re: Need help , newbie cgi
by kabel
in thread Need help , newbie cgi
by britney
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |