in reply to Adding an entry count for each DB
Then later in the code you can refer to each element like this:sub get_items { my $category = shift; open(DATAFILE,"$catagory.dat") or return undef; my @fields = qw/time name email phone subject data passwd picture pr +iceline/; my @items = (); while (<DATAFILEIN>) { chomp; my %hash = (); @hash{@fields} = split /=/, $_; push @items, \%hash; } return @items; }
In this case, the structure is already suitable for HTML::Template. But this way accessing the data is highly logical and much more reusable, with the named attributes, instead of putting everything in a variable name in your while loop. Maintaining the code through changes in your flatfile format will be easier.print $items[$i]{time}; print "There are " . scalar(@items) . " items\n"; # etc..
blokhead
|
|---|