in reply to hard/symbolic reference confusion

Dominus has written a good reference tutorial that you might want to look at.

In general, almost all uses of symbolic references would be better implemented as keys in a regular hash. So your question should really be "Why would you ever need to use a *symbolic* referece?"....

-Blake

  • Comment on Re: I hope this question isn't too basic...

Replies are listed 'Best First'.
Re: Re: I hope this question isn't too basic...
by Sweeper (Pilgrim) on Sep 21, 2001 at 09:36 UTC
    Not only Dominus has written a good reference tutorial, but he also has written some stuff explaining Why it is stupid to use a variable as a variable name. In other words, think before you use symbolic references. Up to now, I have never encountered a situation where symbolic references cannot be replaced by a hash.
Re: Re: I hope this question isn't too basic...
by jupe (Beadle) on Sep 20, 2001 at 22:33 UTC
    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?
      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!
      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!