Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Ternary Quizical behaviour?

by perlfan (Vicar)
on Jul 10, 2020 at 12:27 UTC ( [id://11119136]=note: print w/replies, xml ) Need Help??


in reply to Ternary Quizical behaviour?

'b' => exists($tests{'b'}) && defined($m=$tests{'b'}) ? $m : 0,
needlessly superfulous and relies on a side effect I'm a little wary of; do:

'b' => (defined $tests{'b'}) ? $tests{'b'} : 0,
But since the default is 0, this should mitigate the need for defined:

b => $tests{b} // 0,

Also, defined($m=$tests{'b'}) smells a little funny; I get what you're doing but it is unnecessary.

Update - I am confused but the need for $m. It's getting set twice in your original code, both times based on the state of $tests{'b'}, then you set it to 10. What are you trying to do? Is this your real code or a contrived example?

Replies are listed 'Best First'.
Re^2: Ternary Quizical behaviour?
by Eily (Monsignor) on Jul 10, 2020 at 12:40 UTC

    But since the default is 0, this should mitigate the need for defined
    I don't understand what you mean here. As far as I know, defined $test{'a'} ? $test{'a'} : 0 and $test{'a'} // 0 are strictly equivalent.

    Beyond that ++ for the answer, the use of // here is a clear winner :)

      I just said what you made clear, but I did so in a very awkward way. Thanks for the ++! :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-19 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found