Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: += a hash slice?

by kroach (Pilgrim)
on Jun 01, 2015 at 12:48 UTC ( #1128557=note: print w/replies, xml ) Need Help??


in reply to += a hash slice?

How about something like this?

use strict; use warnings; use Data::Dumper; my %totals; for (1 .. 10) { my @plus = (1, 2, 3); @totals{qw(a b c)} = map { $_ + shift @plus } @totals{qw(a b c)}; } print Dumper \%totals;

The map will add the first element of @plus to each element of the slice in order. However, since the first element gets shifted, $totals{a} gets incremented by 1, $totals{b} by 2 and $totals{c} by 3.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1128557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2020-10-19 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (204 votes). Check out past polls.

    Notices?