in reply to '||' vs 'or' with subroutines
Precedence. 'or' has a higher precedence as '=', but '||' has a hihger precedence. Both operators force scalar context, but:
@foo = @bar or warn "Oeps";
can be read as
(@foo = @bar ) or warn "Oeps";,
assigning the contents of @bar to @foo and then evaluating the array @foo in scalar context, resulting in the length of @foo.
On the other hand,
@foo = @bar || warn "Oeps";
will be evaluated as:
@foo = (@bar || warn "Oeps";
assigning the length of @bar (if it has any!) to the first element of @foo.
HTH Paul
|
|---|