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

Re: Is there something that can turn a coderef undef from inside the coderef?

by BrowserUk (Patriarch)
on Jun 10, 2011 at 23:51 UTC ( [id://909230]=note: print w/replies, xml ) Need Help??


in reply to Is there something that can turn a coderef undef from inside the coderef?

Like this maybe?

sub a{ print 'from a'; undef $_ };; sub b{ print 'from b'; undef $_ };; @r = ( \&a, \&b );; $_->( 1 ) for @r;; from a from b $_->( 1 ) for @r;; Use of uninitialized value in subroutine entry at (eval 13) Undefined subroutine &main:: called at (eval 13)

Basically $_ becomes an alias to the stored coderef. If the code called assigns to $_ without localising it, the coderef will be overwritten.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Is there something that can turn a coderef undef from inside the coderef?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found