in reply to An empty list in boolean context?
I presume you added the third case to show that the value of $_ has no bearing on the first two cases. Here's that fact illustrated a little better:
>perl -MO=Deparse -wle "print defined +() ? 1 : 0" print defined(()) ? 1 : 0; >perl -MO=Deparse -wle "$_ = 1; print defined +() ? 1 : 0" $_ = 1; print defined(()) ? 1 : 0; >perl -MO=Deparse -wle "$_ = 1; print defined () ? 1 : 0" $_ = 1; print defined $_ ? 1 : 0;
Update: Why are you checking for defined? define accepts a scalar, not specifically a boolean. False is defined, so your tests should all print 1 if you were truly examining lists in boolean contexts. (False is 0 in numerical context and "" in string context.) To check the value of a list in a boolean context, simply run the following:
>perl -wle "print(()?'True':'False');" False
I think your question is invalid. Just like there's no such thing as a list in scalar context, I'm guessing that there is no such thing as a list in a boolean context. It's up to the functions returning lists to provide the value.
|
|---|