in reply to Re: Autovivification with hash of hashes
in thread Autovivification with hash of hashes
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 |