tevus_oriley has asked for the wisdom of the Perl Monks concerning the following question:
%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.
sample log lines: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; } }
so for example, when the array of hashes is created, one of the hashes in the array would be483 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
any thoughts?@report = ( { #### 2 or fields2, something like that dx-32 => 2, dx-14 => 1, }, { #### fields3, and so on
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: array of hashes, categorized by array index
by BrowserUk (Patriarch) on Jun 26, 2013 at 21:32 UTC | |
|
Re: array of hashes, categorized by array index
by LanX (Saint) on Jun 26, 2013 at 21:29 UTC | |
by tevus_oriley (Novice) on Jun 27, 2013 at 15:28 UTC | |
|
Re: array of hashes, categorized by array index
by Eily (Monsignor) on Jun 26, 2013 at 21:50 UTC | |
|
Re: array of hashes, categorized by array index
by bdalzell (Sexton) on Jun 26, 2013 at 22:52 UTC | |
|
Re: array of hashes, categorized by array index
by locked_user sundialsvc4 (Abbot) on Jun 26, 2013 at 23:58 UTC |