Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

RE: undefs and functions

by Anonymous Monk
on Aug 02, 2000 at 19:50 UTC ( #25753=note: print w/replies, xml ) Need Help??


in reply to undefs and functions

I often have the same problem with objetcs, stuff like: $elt->first_child->text in an XML tree, which crashes if $elt has no first child. In that case I would like to get just undef, but I still want to be able to test $elt->first_child and have it return a false value when there is no first_child.

As a good monk the nicest solution would be to bless something false!

A false value lessed into the appropriate object class would work just fine.

Of course you can't do that! Traces of Larry's religious faith I guess...

So the next solution I see is to create a new pragma, something like use default_undef_methods which would just default methods on undef objects to undef. I'll get to it as soon as I've got a minute!

Would that solve your problem?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2022-12-06 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?