in reply to Re^2: regex syntax and idomatic Perl
in thread regex syntax and idomatic Perl
... 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: <%-{-{-{-<
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: regex syntax and idomatic Perl
by haukex (Archbishop) on Mar 22, 2017 at 22:04 UTC | |
by cbeckley (Curate) on Mar 22, 2017 at 23:33 UTC | |
by haukex (Archbishop) on Mar 23, 2017 at 11:20 UTC | |
by cbeckley (Curate) on Mar 23, 2017 at 14:44 UTC | |
by AnomalousMonk (Archbishop) on Mar 23, 2017 at 01:43 UTC | |
by cbeckley (Curate) on Mar 23, 2017 at 02:05 UTC | |
Re^4: regex syntax and idomatic Perl
by cbeckley (Curate) on Mar 23, 2017 at 02:26 UTC |