XP is just a number | |
PerlMonks |
OO-call bug uncovered & autovivified functions: defined? exists?by perl-diddler (Chaplain) |
on Oct 28, 2007 at 21:53 UTC ( [id://647749]=perlquestion: print w/replies, xml ) | Need Help?? |
perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:
I figured out the bug in perl that I mentioned a while back regarding OO-methods not being called when I expected them to. They also raise an interesting question about desirable behavior. The question about behavior first, followed by the code showing the bug(s) & probs.
What does it mean to "autovivify" a function -- i.e. how would one use such functionality (or is anyone using such?). If you believe autovivifying a function is a useful feature, then shouldn't you be able to use "exists" to see if the function actually exists yet (if the function has been initialized with a value). Currently, "exists()" only works on arrays and hashes. How would you code it? If you allow exists to work with a function or method call, then shouldn't you also allow exists to work with autovivified scalars? It would mean the same thing as for array or hashes: returns true if the specified scalar has ever been initialized & the scalar (or function) is not autovivified if it doesn't exist. Maybe the parser would be smart enough to figure things out, but it seems the construct "$a=exists &b", would normally be thought to invoke "b" -- not what is wanted. So would you need to encode the function name in a string, ala: "$a=exists '$b'"? What about scalars -- same problem? Or would the parser figure out scalars the same way it does now with array and hash refs ("exists $hash{$key}"). It might mean (if I understand), that "exists $b" tests if "$b" has ever been assigned a value. What'cha think? Here's the code demonstrating the problems (3 cases, 4 if you count the "exists" issue). Linda
p.s. -- shouldn't "code" sections be displayed with a fixed font? Seems like my columns don't line up in the code above when I preview it...*sigh*
Back to
Seekers of Perl Wisdom
|
|