Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

if i have the variable structure like this :
$VAR1 = { 'href' => 'site/other/setup.htm' }; $VAR2 = ' ';
how do i access "href" value !!!

my code is like this ....

my($tag, $attrHash) = @_; print Dumper $attrHash."\n";
when i view the structure of variable $attrHash (i,e by using Dumper) i got the above o/p. Do u know how to get the href value from the above structure.

It's very urgent .....

Thanks n regards,
Danny Appaiah.

edited: Wed Oct 16 16:15:05 2002 by jeffa - s/blah blah//g (code tags)

Replies are listed 'Best First'.
Re: Accessing HASH array values !!
by broquaint (Abbot) on Oct 16, 2002 at 08:57 UTC
Re: Accessing HASH array values !!
by Anonymous Monk on Oct 16, 2002 at 17:40 UTC
    $VAR1 contains a *reference* to a hash - when you do
    { 'href' => 'site/other/setup.html' }
    you create a *reference* to an anonymous hash, and when you assign that to $VAR1, you make the value of $VAR1 a reference to a hash. So, since $VAR1 is a reference to a hash, to use that reference to refer to the hash, you do
    print $VAR1->{'href'};
    and that will print 'site/other/setup.html'.

    HTH.
Re: Accessing HASH array values !!
by meetraz (Hermit) on Oct 16, 2002 at 21:40 UTC
    Then there is the slightly less readable:
    print ${%$VAR1}{'href'};
    or the long-winded
    my %hash = %$VAR1; print $hash{'href'};