Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
... I'm not sure why defined/undef &{'walk'} are allowed.

I'm sure others can cite a precise historical development of the usage of strictures, but for me it's a question of expedience.

The use of symbolic references is not discouraged because symbolic references are Evil, but because in certain cases experience has shown them to cause much trouble. These particular cases are foreclosed by  use strict 'refs';

Some cases are both useful and entirely safe. Testing for the definition of a subroutine with
    defined &{ 'subroutine_name' }
is obviously so.

An indispensable use is the very creation of a hard reference in the first place. It's hard to see how some statement like
    my $coderef = \&{ 'subroutine_name' };
is not going to be involved. Indeed, all the following work (and why should they not?)
    my $coderef = \&subroutine_name;
    my $coderef = \&{subroutine_name};
    my $coderef = \&{ 'subroutine_name' };
although  &{subroutine_name} produces an "Ambiguous use of..." warning.

The final case you mention is the potentially very useful  undef &{ 'subroutine_name' };   One can imagine doing this via a hard reference, e.g.
    my $coderef = \&{ 'subroutine_name' };
    undef $$coderef;
or some such roundabout implementation (that one doesn't actually work, BTW), but what would be the point? After all, it's the name of the subroutine that ultimately has to be undefined; just going to the address of the actual code and scribbling something over it (a return? a jump to an exception?) would not seem to gain you very much.

Anyway, my USD0.02.


In reply to Re: undef/defined &{$name} while "strict refs" by AnomalousMonk
in thread undef/defined &{$name} while "strict refs" by anazawa

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 chanting in the Monastery: (6)
    As of 2014-10-01 07:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (389 votes), past polls