Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Ternary Quizical behaviour? (updated)

by LanX (Saint)
on Jul 10, 2020 at 12:22 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11119135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 10:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found