# Folks, just a note.
# I thought that the
# if (EXPR)
# is supposed to evaluate the EXPR in scalar context, right?
# Well, it does so in most cases
# Except when you do an assignment to a list, when
# instead of evaluating a list as its last element - it evaluates
# the number of elements (like an array) (see Example_5 below).
# This is probably what you would want to test (if list empty or not)
#
# Any comments?
print "Example_1: non-empty array is evaluated as number of elements:\n";
@arr = (undef); # non-empty
if( @arr ){print"true\n"}else{print"false\n"} # true
print "Example_2: a list is evaluated as its last element:\n";
if( (1,undef) ){print"true\n"}else{print"false\n"} # false
print "Example_3: assignment to a scalar: assign - then evaluate:\n";
if( $aa = undef ){print"true\n"}else{print"false\n"} # false
print "Example_4: assignment to an array - assign then evaluate the length:\n";
@ar1 = (); @ar2 = (); # empty array
if( @ar1 = @ar2 ){print"true\n"}else{print"false\n"} # false
@ar1 = (); @ar2 = (undef); # non-empty array
if( @ar1 = @ar2 ){print"true\n"}else{print"false\n"} # true
print "\nExample_5: Here goes the tricky part.\n";
print "Assignment to a list is TRUE if resulting list is non-empty:\n";
if( ($aa) = () ){print"true\n"}else{print"false\n"} # false
@ar = (undef);
if( ($aa) = undef ){print"true\n"}else{print"false\n"} # true ??
if( ($aa) = (undef) ){print"true\n"}else{print"false\n"} # true ??
if( ($aa) = @ar ){print"true\n"}else{print"false\n"} # true ??
print "but note that without assignment it is evaluated normally\n";
if( (undef) ){print"true\n"}else{print"false\n"} # false
__END__
Lev Selector
[EMAIL PROTECTED]
[EMAIL PROTECTED]