http://qs321.pair.com?node_id=909230


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