in reply to eval on hash

I think you've grasped the problem by mentioning eval. $new_hash{ '{key1}{key2}{key3}' } is the actual key you're accessing, which is a Bad Thing™.

You could use eval, but that would be wasteful:
$\ = "\n"; foreach (eval "keys \%{ \$new_hash->$key }" ){ print }
I think it's worth mentioning that %$new_hash and %hash1 are two names for the same thing.

That set aside, here's a solution matching you're concept:
my @path = qw(key1 key2 key3); my $reference = $new_hash; $reference = $reference->{$_} foreach @path; $\ = "\n"; foreach (keys %$reference){ print; }
Update: I suggest rereading perlreftut and perlref to farmiliarise yourself with the concept of pointing at a structure. Perhaps you'll find a more suitable solution.

-nuffin
zz zZ Z Z #!perl

Replies are listed 'Best First'.
•Re: Re: eval on hash
by merlyn (Sage) on Apr 09, 2003 at 17:36 UTC