Mailing List Archive

nil-object
Sorry, this question probably belongs to comp.lang.perl, but I do not have access to that news group, and am in urgent need of an answer.

I need a 'nil' object, that is blessed to a package, but returns false in a conditional (eg if($nilObject)...). How can this be done?


Gerd Knops
gerti@BITart.com
Re: nil-object [ In reply to ]
In article <9509050240.AA10744@homer.bitart.com> you write:
>Sorry, this question probably belongs to comp.lang.perl, but I do not
>have access to that news group, and am in urgent need of an answer.

The group was removed a few weeks ago - it's been replaced with
comp.lang.perl.misc. If that's not on your site, chivvy your admin
people.

>I need a 'nil' object, that is blessed to a package, but returns false
>in a conditional (eg if($nilObject)...). How can this be done?

Well... I'm not an OO guru, but it's my understanding that you
"shouldn't" be tinkering insides of an object, which is what you're
doing in effect. It's "better" to define a method that runs your test
for you, e.g. by returning false if the array's empty. If you don't
allow methods near the "object", then you can just use the null string,
or '0', as usual.

BTW. *do* try to limit the length of the lines in your email!

Ian