Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Ternary Quizical behaviour? (updated)

by LanX (Cardinal)
on Jul 10, 2020 at 12:22 UTC ( #11119135=note: print w/replies, xml ) Need Help??


in reply to Ternary Quizical behaviour?

TL;dr

but that's really what you want or just a C&P disaster? ;)

'b' => exists($tests{'b'}) && defined($m=$tests{'b'}) ? $m : 0, 'a' => exists($tests{'b'}) && defined($m=$tests{'a'}) ? $m : 0, ^^^^^
update

OK now I looked closer, I think you get bitten by passing the same lvalue $m twice in the same statement.

update

yep, seems I'm right, if you force Perl to pass an immutable copy instead of the var it works like expected

use strict; use warnings; use Data::Dump qw/pp dd/; my %tests = ( 'a' => 10, 'b' => 20, ); my $m; # this seems to assign $m once and never bother to check again my %hash; %hash = ( 'b' => exists($tests{'b'}) && defined($m=$tests{'b'}) ? $m : 0, 'a' => exists($tests{'b'}) && defined($m=$tests{'a'}) ? $m : 0, ); pp \%hash; %hash = ( 'b' => exists($tests{'b'}) && defined($m=$tests{'b'}) ? (0+$m) : 0, 'a' => exists($tests{'b'}) && defined($m=$tests{'a'}) ? (0+$m) : 0, ); pp \%hash; %hash = ( 'b' => exists($tests{'b'}) && defined($m=$tests{'b'}) ? "$m" : 0, 'a' => exists($tests{'b'}) && defined($m=$tests{'a'}) ? "$m" : 0, ); pp \%hash;
{ a => 10, b => 10 } { a => 10, b => 20 } { a => 10, b => 20 }

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11119135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2020-09-21 19:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (127 votes). Check out past polls.

    Notices?