Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Re: Array to hash refs

by BrowserUk (Patriarch)
on Aug 14, 2002 at 08:06 UTC ( #190003=note: print w/replies, xml ) Need Help??

in reply to Re: Array to hash refs
in thread Array to hash refs

Even with jeffa's notes below, it still took me a while to wrap this around my brain but when I had, I came up with this....

my @array = qw /a b c d e f/; my $hash; my $val = 1; ($hash->{pop @array}, $val, $hash) = ($val, $hash, undef) while @array +; $hash = $val;

Which is slightly cleaner?, but that final assignment stood out so...

my @array = qw /a b c d e f/; my $hash = 1; my $tmp; ($tmp->{pop @array}, $hash, $tmp) = ($hash, $tmp, undef) while @array +;

Slightly non-intuative to assign the value to the hashref at the start but...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2023-03-31 18:43 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (76 votes). Check out past polls.