... the fact that this operator can evaluate to an lvalue now prompts the next question, where else does this occur? Does any expression that evaluates to a object or variable work the same way?
Interesting question. All the more so since I have only a tenuous grasp of the syntactic/semantic issues involved. Obviously, something like
doesn't work: ($t || $f) can't be an lvalue.c:\@Work\Perl\monks>perl -wMstrict -le "my $t = 1; my $f = ''; ;; ($t || $f) = 'foo'; print qq{t '$t' f '$f'}; " Can't modify logical or (||) in scalar assignment ... Execution of -e aborted due to compilation errors.
The only other situation I can think of in which this sort of hocus-pocus occurs is with Lvalue subroutines (see perlsub). I'd be interested to learn if there are any others. (Of course, now that I've asked the question, folks will probably respond with a million examples! :)
BTW: the ?: ternary operator in C/C++ has the same lvalue selection property.
Give a man a fish: <%-{-{-{-<
In reply to Re^3: regex syntax and idomatic Perl
by AnomalousMonk
in thread regex syntax and idomatic Perl
by cbeckley
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |