I have a log file I am parsing that will eventually become a report. I split each line of the log file into its individual fields, and ran select fields into a hash.
%report = (); while (my $line = <$log_file>) { my @fields = (split / /, $line); $report{$_}++ foreach @fields[2,4,5,9,7,1]; }

That works fine... and then I realized I need each field categorized for the reporting part later. I think I need an array of hashes; but I can't figure out how to name each hash after the index number of the @fields array as I'm creating it. The existing hash above could be changed to the main array @report. Then each of the selected index numbers would become the name of a different hash within @report.

The following horrible code creates hashes for each line of input instead of a hash for each selected field.

my @report; while (my $line = <$log_file>) { my @fields = (split / /, $line); foreach (@fields[2,4,5,9,7,1]) { my %hash; foreach (@fields[2,4,5,9,7,1]) { $hash{$_}++; } push @report, \%hash; } }
sample log lines:
483 OS dx-32 1 charles list4 aardvark.com ty-off lx-on C 01 483 DS dx-14 1 james list3 23.456.12.7 ty-on lx-on B 01 769 XO dx-32 5 sully nolist widgets.com ty-on lx-on V 07
so for example, when the array of hashes is created, one of the hashes in the array would be
@report = ( { #### 2 or fields2, something like that dx-32 => 2, dx-14 => 1, }, { #### fields3, and so on
any thoughts?

In reply to array of hashes, categorized by array index by tevus_oriley

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.