Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Ternary Quizical behaviour?

by perlfan (Priest)
on Jul 10, 2020 at 12:27 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2020-09-21 20:05 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (127 votes). Check out past polls.