http://qs1969.pair.com?node_id=25753


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?