[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] Re: macperl-anyperl-digest V1 #24



Excerpt of message (sent 30 June 1999) by Jeremy Andrews:
> I've got a couple more questions...
> 
> > > 	unless (@directories eq "") {
> >
> >@directories will _never_ eq "".

 
> I read early on that the way Perl parses variables makes "0" = a
> boolean FALSE = "" (null).

In boolean context, "" and "0" (and 0) are equivalent.  In numeric
context, they would be, too (with a warning).  But with the eq
operator you enforce string context, which has 0 (scalar context =>
the number of elements in the list) converted to "0" and compares it
to "", a obviously different string.

You say you tested this by setting a scalar to 0 and "" and found that
>   if ($foo) { &foo; }
works as expected.  Now here you evaluate it in boolean context, in
contrast to above.  You're right, this here is simpler, so why did you 
use the 'eq ""' above?

Why did you put in that 'unless ...' line at all?  It looks useless.
Simpler is better.

	Christian Brechbühler

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org