Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: better array to hash conversion

by Anonymous Monk
on Dec 11, 2012 at 15:14 UTC ( #1008321=note: print w/replies, xml ) Need Help??

in reply to better array to hash conversion

While the hash slice method is the most idiomatic, here's one more variation, based on the OP's code -- just taking out the C-like for loop:

$hash{ $array[$_] } = $_ for (0..$#array);

And something that works only after 5.12 but is very easy to read:

use 5.012; while (my ($idx, $val) = each(@array)) { $hash{$val} = $idx; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008321]
[marioroy]: LA only $ and \ needed backslash, not ' and ".
[marioroy]: my @music_times = qx(find \$HOME/Music/ Albums -type f -iname '*.mp3' -exec mp3info -p "%S\\n" {} \\;);
[marioroy]: I wanted to come back and report on that.
[marioroy]: cheers

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-04-23 22:36 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (433 votes). Check out past polls.