SPUG: Behavior of &&'ed functions

John Costello cos at indeterminate.net
Wed Oct 27 15:20:50 CDT 2004


I have some code which boils down to the example shown below.  I expected 
to see four lines of output, with $column incremented twice.  Instead, the 
first print statement in each block does not output.  Instead, the second 
and third lines are performed and apparently the first print outputs the 
boolean evaluation of &&'ed statements.  Why does Perl (5.8.0) behave this 
way?

Enlightenment appreciated.

John


#!/localdepot/perl-5.80/bin/perl -w
# test6.pl
use strict;

my ($column);

$column = 0;

print "column is: $column\n"
&& ++$column
&& print "now column is: $column\n";

print "and column is: $column\n"
&& $column++
&& print "and now column is: $column\n";



> ./test6.pl
now column is: 1
1and now column is: 2
1



-----
John Costello - cos at indeterminate dot net
"If you are afraid of butter, use cream."--Julia Child



More information about the spug-list mailing list