Hi Stan, Please check my comments below: On Tue, Apr 3, 2012 at 10:39 PM, Stan N/A <stan...@gmail.com> wrote:
> I've run into a weird issue where the ternary operator isn't doing > what I believe it normally would and need some help understanding the > issue. I'm sure I'm missing some critical point, but perhaps this is > an issue with perl. Here's a short 14 line script exemplifying the > issue: > > -----code----- > #!/usr/bin/perl > use strict; > use warnings; > > my %test = ( > one => "first", > two => "second" > ); > > $test{one} eq "first" ? > $test{one} .= " is the worst\n" : > $test{two} .= " is the best\n"; > $test{one} eq "first" ? $test{one} .= " is the worst\n" : ( $test{two} .= " is the best\n"); > print $_ for values %test; > **OUTPUT** first is the worst second ----code---- > > I believe the output should result with: > > first is the worst > second > > The output I receive running this test is: > > first is the worst > is the best > second > > This seems peculiar! Help! > It isn't, "..conditional operator binds more tightly than the various assignment operators,.. so using embedded assignments without parentheses will get you into trouble.." Programming Perl 3rd Edition. You can also see perldoc perlop, under *Conditional Operator* sub-topic. > Stan > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- Tim