Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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 &.


Comment on Re: Is this a symbolic reference?
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://139271]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-07-10 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (197 votes), past polls