Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: quick question about hash element access

by cLive ;-) (Prior)
on Jun 27, 2003 at 22:52 UTC ( [id://269771]=note: print w/replies, xml ) Need Help??


in reply to quick question about hash element access

Nice question :) I had a play using the lovely AUTOLOAD.
#!/usr/bin/perl use strict; use warnings; our $AUTOLOAD; our $hashref = { 'a' => { 'b' => { 'c' => 'this is c', 'd' => 'this is d' } } }; print "a_b_c() = ".a_b_c()."\n"; print "a_b_d() = ".a_b_d()."\n"; exit(0); sub AUTOLOAD { my ($package,$ref_name) = split /::/, $AUTOLOAD; my $ref = '$hashref'. join '', map { "->{$_}" } grep /^\w+$/, spli +t /_/, $ref_name; return eval $ref; } # output for above is: a_b_c() = this is c a_b_d() = this is d

.02

cLive ;-)

Log In?
Username:
Password:

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

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

    No recent polls found