develooper Front page | perl.beginners | Postings from April 2012

Using the ternary operator to concat a string not working like I think?

Thread Next
From:
Stan N/A
Date:
April 3, 2012 14:39
Subject:
Using the ternary operator to concat a string not working like I think?
Message ID:
CACT5FVNnyHo8wJoJJbWgFfAFSv1UBoGmoJVXtjGDrk+NyR2bqg@mail.gmail.com
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";

print $_ for values %test;
----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!

Stan

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About