in reply to symbolic references

Because that isn't a symbolic reference, it doesn't use any symbols

Replies are listed 'Best First'.
Re^2: symbolic references
by Anonymous Monk on Jan 01, 2011 at 07:31 UTC
Re^2: symbolic references
by 7stud (Deacon) on Jan 01, 2011 at 08:33 UTC

    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.

      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.
Re^2: symbolic references
by ikegami (Patriarch) on Jan 02, 2011 at 21:15 UTC

    It sure is a symbolic reference.

    >perl -e"use strict 'refs'; ${'foo'} = 1;" Can't use string ("foo") as a SCALAR ref while "strict refs" in use at + -e line 1. >perl -e"use strict 'refs'; &{'foo'}" Can't use string ("foo") as a subroutine ref while "strict refs" in us +e at -e line 1. >perl -e"use strict 'refs'; goto &{'foo'}" Goto undefined subroutine &main::foo at -e line 1.

    You can dereference references and strings. We call the latter "symbolic references" because the reference is a symbol name rather than a true reference. It doesn't matter whether the string is returned from a variable, a string literal or some more complex expression.