Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: perl syntax help for ternary operator

by AnomalousMonk (Archbishop)
on Oct 09, 2014 at 12:59 UTC ( [id://1103295]=note: print w/replies, xml ) Need Help??


in reply to perl syntax help for ternary operator

Here's how ternary operators can be chained. (And yes, wrapping this up in a subroutine is a very good idea, but the operator chain itself could be in-lined.)

c:\@Work\Perl>perl -wMstrict -le "my $s = qq{a ${ \str('tilt2') } operation needs @{[ str('x') ]} help} +; print qq{'$s'}; ;; sub str { my ($s) = @_; ;; return $s eq 'level3' ? 'level3 stage' : $s eq 'tilt2' ? 'tilt2 snafu' : ! defined $s ? 'undefined' : qq{Edit '$s'} ; } " 'a tilt2 snafu operation needs Edit 'x' help'
See Conditional Operator in perlop.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-03-28 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found