in reply to variable interpolation while dereferencing

You only need to have the variables evaluate to the keys. What you try doesn't give the compiler enough clues, it thinks the variable is to be the name of a method.

my $top = 'person'; my $foo = 'name'; print $ref->{$top}{$foo};

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: variable interpolation while dereferencing
by arc_of_descent (Hermit) on Oct 27, 2002 at 11:49 UTC
    Hi,

    But i want to access the hash reference through a
    variable as i don't know how deep it may go!

    Like the following:

    sub add_folder("Linux/Kernel") { # i want to do the foll. # $bkref->{folder}{Linux}{folder}{Kernel}{folder} = {}; }

    So, the RHS may go to any size
    and i can't hard code it
    Can u help me out?

    --
    arc_of_descent

      As hint:

      my $path = 'A/B/C'; my $hr = { 'A' => {'B'=>{'C'=>'Hello'}}}; my @path = split m</>,$path; my $ref = $hr; while(@path){ $ref = $ref->{ shift @path } } print "$ref\n"
      --
      http://fruiture.de

        thanx!
        I've spent my whole sunday morning and afternoon
        trying to get it to work!


        --
        arc_of_descent