Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: Is this a symbolic reference?

by danger (Priest)
on Jan 16, 2002 at 23:39 UTC ( [id://139303]=note: print w/replies, xml ) Need Help??


in reply to Re: Is this a symbolic reference?
in thread Is this a symbolic reference?

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://139303]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-26 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found