Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: += a hash slice?

by kroach (Pilgrim)
on Jun 01, 2015 at 12:48 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1128557]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-25 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found