Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Is this a symbolic reference?

by clintp (Curate)
on Jan 16, 2002 at 22:36 UTC ( #139271=note: print w/replies, xml ) Need Help??

in reply to Is this a symbolic reference?

Now to really get your shorts in a twist:

goto &{"foo"}

Clearly has the form of a symref, and should be caught by strict -- but it's not. This was reported by me and mjd to p5p a while ago and it's an intentional exception to stricture. References: my report, mjd's report of nearly the same thing, the eventual explanation. The short version is that strict refs only applies to $%@* things, not &.

Replies are listed 'Best First'.
Re: Re: Is this a symbolic reference?
by danger (Priest) on Jan 16, 2002 at 23:39 UTC
    The short version is that strict refs only applies to $%@* things, not &.

    Your short version seems to be a little too short perhaps:

    #!/usr/bin/perl -w use strict; sub foo { print "foo: @_\n" } my $symbolic = 'foo'; # This symbolic method invocation works in 5.6.1 # (but not in 5.00503) main->$symbolic; # foo: main # 'goto &$symbolic' works (in subroutines) sub bar { goto &$symbolic; # works # goto &{'foo'}; # works } bar(1,2,3); # But these symref calls don't work: &$symbolic; # ack! &{$symbolic}; # ook! &{"foo"}; # eek!

    There clearly appears to be an exception for goto &{"symref"} in terms of symbolic-ref style *calls*.

    The report you gave was slightly different --- taking a reference to a symbolically dereferenced subroutine works:

    use strict; sub foo { print "foo: @_\n"; } my $bar = "foo"; &foo; # works # &{$bar}; # ack! symref as a call doesn't work my $sref = \&{$bar}; # works! $sref->(1,2,3); # foo: 1 2 3

    The symbolic-deref for the purpose of taking a ref does indeed appear to be an exception that applies to & but not $%@*:

    use strict; my $foo = "this is foo"; my $bar = "foo"; my $ref = \${$bar}; # ack!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://139271]
[choroba]: I don't even remember the beginning
[choroba]: someone told me to use perl instead of sed for something, and several years later, I'm developing a huge Tk application
[Discipulus]: choroba started in primary school to get some advantage in the future..
[choroba]: nono, I programmed in Basic at the primary school, on my Commodore 116/16
[Discipulus]: ;=)
[choroba]: then learned some assebly on the same machine, then moved to my father's PC (XT with a Hercules card), used Turbo Pascal a lot
[choroba]: I started with *nix at the University, we had some Sparcs and Linux machines
[choroba]: that was around 1994 or 95

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2018-06-22 09:37 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (123 votes). Check out past polls.