> if ( ! defined $x )

I read up on defined and undefined. But I'm looking for a test that will 
this return true or false to a var condition:
 ...
 sub isNULL
 {
   return undefined $_[0] && $_[0] eq '' $_[0] eq "";
 }
 # my goal is all three return the same as
 # my proposed sub isNULL()
 my $x;   # undefined
 $x="";   # zero length
 $x='';   # zero length
 ...

Would the new sub do or is there a better?

-rkl

>> Can someone correct this sub or is it good?
>
> No, I wouldn't call it good.

I didn't mean that this is good code but good enough to work. Apparently
it didn't!

thanks,
-rkl



> On Thursday, October 2, 2003, at 04:25  PM, [EMAIL PROTECTED] wrote:
>
>> I wan to write a sub return true or false if the var was initialized.
>
> We can do that, but I really don't think we need a sub for it, since
> there is a built-in.
>
>> Can someone correct this sub or is it good?
>
> No, I wouldn't call it good.
>
>>  ...
>>  if(isNULL($x) { print "it is null\n");
>
> if ( ! defined $x ) { ... }
>
>>  else          { print "it is NOT null\n");
>>  ...
>>
>> sub isNULL
>> {
>>   return $_[0] =~ //
>
> This Regex doesn't do what you think.  It reuses the last successful
> match.
>
> You don't want a Regex here anyway, you meant:
>
> $_[0] eq '';
>
> Since I could set a variable to the empty string though, that doesn't
> really answer your question.
>
> Hope that helps.
>
> James
>
>> }
>>
>> thanks,
>> -rkl
>>
>> --
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to