in reply to Re: Re: Re: Re: Re (tilly) 3: hash/array
in thread hash/array

In general, you need an array of records.
my @records; while(<FILE>) { chomp; my @courow = split(/\t/); if ($courow[0] eq $courowid) { my %coudata; @coudata{@coufields} = @courow; push @records, \%coudata; } } # and further down for my $ref (@records) { my %coudata = %$ref; print ul( map { li("$_: $coudata{$_}") } keys %coudata); print ("<br>" x 3); }
Of course I'm not suggesting you use that as is.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re (tilly) 3: hash/array
by malaga (Pilgrim) on Feb 02, 2001 at 03:31 UTC
    that did the trick. thanks! it looks like this now:
    sub getrows { my @records; my $value = param('name'); my $rowid = $ARGV[0] || $value; my %data = (); my @fields = split(/\t/, <FILE>); chomp @fields; while(<FILE>) { chomp; my @row = split(/\t/); if ($row[0] eq $rowid) { my %data; @data{@fields} = @row; push @records, \%data; } } close (FILE); print header; for my $ref (@records){ my %data = %$ref; print ul( map { li("$data{$_}") } keys %data); } }
    now i have to make it print nicely in tables. back to work.