Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: ternary conditional help

by BillKSmith (Monsignor)
on Nov 29, 2016 at 03:59 UTC ( [id://1176765]=note: print w/replies, xml ) Need Help??


in reply to ternary conditional help

The operator is intended to return a single value. Attempting to get side effects is a bad idea even if you succeed. Here is how to get the result you desire.
use strict; use warnings; my $logical = 1; my ($a,$b); $a = $logical ? 2 : 'a'; $b = $logical ? 'b' : 'x'; print "a is $a\n"; print "b is $b\n"; $logical = 0; print "\$logical is now false\n"; $a = $logical ? 2 : 'a'; $b = $logical ? 'b' : 'x'; print "a is $a\n"; print "b is $b\n"; OUTPUT: a is 2 b is b $logical is now false a is a b is x
Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found