Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Working on hash slice

by AnomalousMonk (Archbishop)
on Mar 12, 2019 at 23:34 UTC ( [id://1231186]=note: print w/replies, xml ) Need Help??


in reply to Working on hash slice

I agree that the method hippo shows here is best, but another (also non-destructive) way to initialize a hash at declaration from a pair of arrays (of equal size) is:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "use List::MoreUtils qw(zip); ;; my @players = qw/ barney fred dino/; my @bowling_scores = (195, 205, 30); ;; my %score = zip @players, @bowling_scores; dd \%score; " { barney => 195, dino => 30, fred => 205 }
(Assumes initializing arrays are of equal size!) See List::MoreUtils::zip().


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found