Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Re: quick question about hash element access

by Chmrr (Vicar)
on Jun 28, 2003 at 01:11 UTC ( #269787=note: print w/ replies, xml ) Need Help??


in reply to Re: quick question about hash element access
in thread quick question about hash element access

And with very few changes you can make it an lvalue, so you can use it to assign to:

sub nested : lvalue { @_ == 1 ? $_[0] : nested($_[0]{$_[1]}, @_[2..$#_]); }

..and now you can say:

nested(\%hash, a => b => c =>) = "VALUE";

TThis can lead to such fun looking constructs as nested $hashref, a => b => c => d => = 42; Note that this code will only work under perl 5.6.0 or later, though; earlier perls had more restricted definitions of lvalues. See also descending a tree of hash references.

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'


Comment on Re: Re: quick question about hash element access
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-09-30 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (383 votes), past polls