Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Autovivification with hash of hashes

by Cabrion (Friar)
on Jan 26, 2003 at 01:38 UTC ( [id://229916]=note: print w/replies, xml ) Need Help??


in reply to Re: Autovivification with hash of hashes
in thread Autovivification with hash of hashes

The use of eval might be in order here to programtically build up:

if(exists($foo{bar}) and exists($foo{bar}{baz})) { print "\$foo{bar}{baz} exists\n"; }

by doing soemthing like this:

my @levels = qw/bar baz/; foreach(@levels) { $_ = 'exists('.$_.')'; } my $code = '('.join(' and ', @levels).')'; #$code is now: (exists($foo{bar}) and exists($foo{bar}{baz}) if (eval $code) { #do whatever }

Note that the order of @levels is important.

Replies are listed 'Best First'.
Re: Re: Re: Autovivification with hash of hashes
by BrowserUk (Patriarch) on Jan 26, 2003 at 01:53 UTC

    No need to pay the penalty of eval, see Aristotle's exists_novivify sub


    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Log In?
Username:
Password:

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

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

    No recent polls found