the problem arises NOT from the fact that you consider yourself a "cgi newbie". your data structure is too flat :) i used a HoH for that. the first hash is "entered" with the name and returns another hash which is "entered" by the state.
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"; }
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.

In reply to Re: Need help , newbie cgi by kabel
in thread Need help , newbie cgi by britney

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.