On Sun, Feb 10, 2013 at 8:05 AM, Chris Stinemetz <chrisstinem...@gmail.com>wrote:
> To take this a step further. > > How would you go about creating a hash to sum up all the values in group > $3 utilizing the flip/flop operator and print the results of the key and > value with the key being group $2? > > This is what I came up with and seems to do the trick. Hopefully it can help someone else. my %hash; while (<DATA>) { if ( /0x3\|68\|/ .. /^#END/ ) { if (/\|(\d)\|(\d+)\|(\d+)/) { my @cols = ( $1, $2, $3 ); $hash{ $cols[1] }{instance}++; $hash{ $cols[1] }{volume} += $cols[2]; } } } ## header print join(",", qw( Peg Instance Subtotal )), "\n"; foreach ( sort { $a <=> $b } keys(%hash) ) { print join( ",", $_, $hash{$_}{instance}, $hash{$_}{volume} ), "\n"; }