I would suggest using some sort of nested structure to organize your data. Read all your flatfiles into data structures, then manipulate them in another part of the code. Perhaps even translate them into a structure that you can pass to HTML::Template (look into this, it will make your life easier). Something like this (untested):
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; }
Then later in the code you can refer to each element like this:
print $items[$i]{time}; print "There are " . scalar(@items) . " items\n"; # etc..
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.

blokhead


In reply to Re: Adding an entry count for each DB by blokhead
in thread Adding an entry count for each DB by lisaw

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.