in reply to ternary conditional help
In addition to the deparse examples provided by haukex here, consider the OPed code and a slight modification. In the first, original version, constant folding (I think that's the correct phrase) makes the ternary go away and reduces the expression to a pure assignment (albeit a two-step one):
Making the condition expression of the ternary non-constant preserves the ternary operator in all its LHS glory:c:\@Work\Perl\monks>perl -wMstrict -MO=Deparse,-p -le "my $a = 'a'; my $b = 'b'; 1 ? $a = 2 : $b = 'x'; print qq{a is $a}; print qq{b is $b}; " BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; (my $a = 'a'); (my $b = 'b'); (($a = 2) = 'x'); print("a is $a"); print("b is $b"); -e syntax OK
Please see O and B::Deparse.c:\@Work\Perl\monks>perl -wMstrict -MO=Deparse,-p -le "my $a = 'a'; my $b = 'b'; my $p = 1; $p ? $a = 2 : $b = 'x'; print qq{a is $a}; print qq{b is $b}; " BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; (my $a = 'a'); (my $b = 'b'); (my $p = 1); (($p ? ($a = 2) : $b) = 'x'); print("a is $a"); print("b is $b"); -e syntax OK
Give a man a fish: <%-{-{-{-<
|
|---|