in reply to Re: symbolic references
in thread symbolic references

According to "Programming Perl 3rd", p 263:

What happens if you try to dereference a value that is not a hard reference? The value is then treated as a symbolic reference.

In the line:

goto &{"greet"};

"greet" is not a hard reference, so what happens when you try to dereference a value that is not a hard reference, e.g. {"greet"}? According to "Programming Perl", the string is treated as a symbolic reference. As far as I can tell, dereferencing the string "greet" is the very definition of a symbolic reference.

It's my understanding that my code tells perl to look in the symbol table for the name "greet" and return the appropriate part of greet's typeglob: the coderef part. On the other hand, a hard reference points directly at the data in memory so a hard reference doesn't need to access the symbol table to find the data.

Replies are listed 'Best First'.
Re^3: symbolic references
by Anonymous Monk on Jan 01, 2011 at 09:12 UTC
    Hahaha, well, greet is a string constant. Its is not a variable; and strict says
    "strict refs" This generates a runtime error if you use symbolic references (see perlref). use strict 'refs'; $ref = \$foo; print $$ref; # ok $ref = "foo"; print $$ref; # runtime error; normally ok $file = "STDOUT"; print $file "Hi!"; # error; note: no comma after $file There is one exception to this rule: $bar = \&{'foo'}; &$bar; is allowed so that "goto &$AUTOLOAD" would not break under stricture.