in reply to Re: I hope this question isn't too basic...
in thread hard/symbolic reference confusion

forgive me if i don't have a clue to what i am talking about, but isn't $foo{boo} a symbolic refernce, while $foo->{boo} a hard reference?
  • Comment on Re: Re: I hope this question isn't too basic...

Replies are listed 'Best First'.
Re: Re: Re: I hope this question isn't too basic...
by blakem (Monsignor) on Sep 20, 2001 at 22:54 UTC
    Nope, take a look at the following code, especially the third stanza:
    #!/usr/bin/perl -wT use strict; # hash key lookup using the actual hash (no reference) my %foo = (bar => 'data'); my $val = $foo{bar}; # fetch the scalar key (hence the '$' infron +t of foo) from the hash print "Val => $val\n"; # hash key lookup using a referent to the hash (hard reference) my %hash = (bar => 'data2'); my $foo = \%hash; my $val2 = $foo->{bar}; # can also be written '$$foo{bar}'; print "Val2 => $val2\n"; # using symbolic (soft) references use vars qw($foo $bar); $bar = 'data3'; $foo = 'bar'; my $val3; { no strict 'refs'; # 'use strict' won't allow this $val3 = $$foo; # find the data by treating the value of $foo +as a var name } print "Val3 => $val3\n"; =output Val => data Val2 => data2 Val3 => data3

    -Blake

      thank you very much for taking the time to answer my questions. your help is very appreciated!
Re: Re: Re: I hope this question isn't too basic...
by dragonchild (Archbishop) on Sep 20, 2001 at 22:59 UTC
    Nope. A symbolic reference is something like:
    $bar = 3; $foo = 'bar'; $baz = $$foo; # This now sets $baz = $bar, or 3.
    Any other reference is a hard reference. $foo{boo} is a hash-access, not a reference at all.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      you guys rule. thanks for taking the time to answer my questions!