Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: elsif stupid question...

by dmorelli (Scribe)
on Apr 28, 2005 at 15:09 UTC ( [id://452334]=note: print w/replies, xml ) Need Help??


in reply to Re: elsif stupid question...
in thread elsif stupid question...

Optionally, the nested ternary is good for long chains of if/elsif/else

#! /usr/bin/perl -w use strict; (my $foo = shift) ||= 0; ($foo == 1) ? print "It's one\n" : ($foo == 2) ? print "It's two\n" : ($foo == 3) ? print "It's three\n" : print "It's nothing meaningful!\n";

Replies are listed 'Best First'.
Re^3: elsif stupid question...
by blazar (Canon) on Apr 28, 2005 at 15:44 UTC
    Personally I try to avoid using?: for its side effects, when not golfing - that is! Re the example you gave, a hash or an array would have provided a much neater solution.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found