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.