in reply to exit EXPR?
What went wrong? perldoc -f exit says that exit evaluates EXPR and exits immediately with that value. My operating system is Debian testing (Jessie).
Indeed, and it does just that. But you're basically doing this:
((exit $var) > $tmp) ? 1 : 0;
In other words, exit is called with $var, and the result is then compared to $tmp, and the whole expression evalutes to 1 or 0... or would, if exit returned at all, which it of course doesn't.
Here's a short illustration of how operator precedence works:
#!/usr/bin/perl use feature qw/say/; use strict; use warnings; sub half($) { return $_[0] / 2; } say half 3 > 2 ? 7 : 5 ; # 5 say half(3 > 2) ? 7 : 5 ; # 7 say half(3 > 2 ? 7 : 5); # 3.5
EDIT: to clarify this a bit more: named unary operators (of which exit is an example) bind more tightly than >, which binds more tightly than ?:, which in turn binds more tightly than list operators do (rightward). So ?: takes precedence over print and say -- but exit takes precedence over ?:.
For more, see the "Operator Precedence and Associativity" table at the top of perlop, as well as chapter 3 ("Unary and Binary Operators") of Programming Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: exit EXPR?
by BillKSmith (Monsignor) on Jul 15, 2014 at 13:58 UTC |