Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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!

In reply to Re: Re: Is this a symbolic reference? by danger
in thread Is this a symbolic reference? by demerphq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2018-11-19 18:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My code is most likely broken because:
















      Results (217 votes). Check out past polls.

      Notices?