On Sun, Sep 11, 2011 at 3:33 PM, Chanan Berler <[email protected]> wrote:
> Hello All,
>
> I have a reference to hash structure, and a path where data is found.
> Is it possible to retrieve the data where path is found ?
>
>
> # What I am looking for:
> my $hash = {
> 'key1' => { 'key11' => 10 },
> 'key2' => { 'key21' => { 'key22' => { 'key23' => 100 }}},
> 'key3' => { 'key31' => { 'key321' => 20,
> 'key322' => 200 }}
> };
>
> # this will not work since it's not referencing to nothing
> my $path = {'key3'}->{'key31'}->{'key321'};
>
> # doesn't work for me :-(
> print $hash->{$path};
>
> # work (but i wanna use $path as location reference)
> print $hash->{'key3'}->{'key31'}->{'key321'};
you can do this:
my $path = "{'key3'}->{'key31'}->{'key321'}";
print eval "\$hash->$path";
thought I find it very dangerous.
Why do you need this?
Gabor
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl