Random_Walk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Folks
I want to do something like this:
use strict; use warnings; use Data::Dumper; my %totals; for(1..10){ @totals{qw(a b c)} += (1,2,3); } print Dumper \%totals;
And end up with
%totals = ( 'a' => 10, 'b' => 20, 'c' => 30, );
But of course I get %totals set to
( 'a' => undef, 'b' => undef, 'c' => 30, );
How would you folks keep such hash of running totals
Cheers,
R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: += a hash slice?
by choroba (Cardinal) on Jun 01, 2015 at 09:13 UTC | |
by Random_Walk (Prior) on Jun 01, 2015 at 13:00 UTC | |
|
Re: += a hash slice?
by hdb (Monsignor) on Jun 01, 2015 at 11:35 UTC | |
by Random_Walk (Prior) on Jun 01, 2015 at 15:10 UTC | |
|
Re: += a hash slice?
by kroach (Pilgrim) on Jun 01, 2015 at 12:48 UTC |