J
Jens Thoms Toerring
Hi,
after gotten bitten by it (again) I wonder once more if
there are good reasons why in
perl -e 'sub x { return 1 and 0 } print x() . "\n";'
the 'return' seems to have a higher "precedence" than the
'and' operator, i.e. () returns 1, while for
perl -e 'sub x { return 1 && 0 } print x() . "\n";'
0 is returned. On the other hand with
perl -e 'print "bla\n" if 1 and 0;'
perl -e 'print "bla\n" if 1 && 0;'
'if' (and 'unless') has a lower "precedence" then both 'and' and
'&&', thus "bla\n" isn't printed out in either case. And the same
holds, of course, for the 'or' and '||' operators...
That doesn't look too logical or intuitive to me, so is there a
reason for that I'm missing to see or is it for some historical
reasons? Is there anything that could happen after a 'return',
so is 'return 1' an expression that has a value that could be
'and'ed with something following it?
Regards, Jens
after gotten bitten by it (again) I wonder once more if
there are good reasons why in
perl -e 'sub x { return 1 and 0 } print x() . "\n";'
the 'return' seems to have a higher "precedence" than the
'and' operator, i.e. () returns 1, while for
perl -e 'sub x { return 1 && 0 } print x() . "\n";'
0 is returned. On the other hand with
perl -e 'print "bla\n" if 1 and 0;'
perl -e 'print "bla\n" if 1 && 0;'
'if' (and 'unless') has a lower "precedence" then both 'and' and
'&&', thus "bla\n" isn't printed out in either case. And the same
holds, of course, for the 'or' and '||' operators...
That doesn't look too logical or intuitive to me, so is there a
reason for that I'm missing to see or is it for some historical
reasons? Is there anything that could happen after a 'return',
so is 'return 1' an expression that has a value that could be
'and'ed with something following it?
Regards, Jens