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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.