Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^7: OO-call bug uncovered & autovivified functions: defined? exists?

by Somni (Friar)
on Oct 29, 2007 at 02:38 UTC ( #647782=note: print w/replies, xml ) Need Help??


in reply to Re^6: OO-call bug uncovered & autovivified functions: defined? exists?
in thread OO-call bug uncovered & autovivified functions: defined? exists?

Hm, so it does. The only non-contrived example I can think of is:

BEGIN { print exists(&frobnicate)?1:0, "\n"; my %OPS = ( frob => \&frobnicate, knob => \&knobnicate, ); sub runops { print $_->(), "\n" for values %OPS } } sub frobnicate { 'frobnicate' } sub knobnicate { 'knobnicate' }

I have done it in the past in order to keep the dispatch table visible only to the function using it, but I find the extra indentation rather ugly so I tend to avoid it. I don't know if I'd call it strange and rare, but it certainly isn't unexpected. The need for it is also removed in 5.10, but I mention this only so that someone else won't.

Edit: I realize now this has gotten somewhat far afield of the original question. You asked me to substantiate that if you remove auto-vivification by reference then all subroutines would have to be defined before they can be referred to. It's true, they would need only be declared, not defined, before taking a reference.

  • Comment on Re^7: OO-call bug uncovered & autovivified functions: defined? exists?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2023-11-30 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?