Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: setting hash keys by array

by broquaint (Abbot)
on Sep 09, 2002 at 16:16 UTC ( [id://196330]=note: print w/replies, xml ) Need Help??


in reply to setting hash keys by array

This seems to do the trick
use Data::Dumper; my @a = split ' ', q[foo bar baz quux]; my $le = my $h = {}; for(0 .. $#a - 1) { $le->{ $a[$_] } = { $a[$_ + 1] => {} }; $le = $le->{ $a[$_] }; } print Dumper $h; __output__ $VAR1 = { 'foo' => { 'bar' => { 'baz' => { 'quux' => {} } } } };
Although are you sure this is the trick you want to be performing?
HTH

_________
broquaint

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-25 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found