in reply to Possible precedence issue with control flow operator
When in trouble with perlop precedence always use parentheses.
> return something() or croak "something didn't work";
equals
( ( return something() ) or ( croak "something didn't work" ) );
But doesn't make much sense, because the or-branch is never reached.
A "normal" return almost never fails, and if return fails, the program dies right away:
> perl return __END__ Can't return outside a subroutine at - line 2.
(update: one might argue that the former shouldn't even compile, but there are probably use-cases in combination with do FILE )
> return something() || croak "something didn't work";
equals
return ( ( something() ) or ( croak "something didn't work" ) );
which looks a bit strange but is somehow possible.
still Carp::croak() means to die
# die of errors (from perspective of caller) croak "We're outta here!";
so returning the value of croak doesn't really make sense either.
The latter means mixing two very different control flows in one line ... irk.
In the spirit of PBP : "make control flows immediately clear!", mixing two is quite confusing for the reader.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|