For a casual counter this might be overkill, but you could use a closure:
use strict; use warnings; use Data::Dumper; sub make_counter { my ( $tally, @labels ) = @_; return sub { $tally->{$_} += shift for @labels } } my %totals; my $counter = make_counter \%totals, qw(a b c); for(1..10){ $counter->(1,2,3); } print Dumper \%totals;
In reply to Re: += a hash slice?
by hdb
in thread += a hash slice?
by Random_Walk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |