Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by BrowserUk (Pope)
on Jun 10, 2011 at 23:51 UTC ( #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
Node Status?
node history
Node Type: note [id://909230]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2021-05-09 17:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (102 votes). Check out past polls.

    Notices?