%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
In reply to array of hashes, categorized by array index by tevus_oriley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |