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

alternative to if statements

by MysticFallout (Initiate)
on Feb 10, 2004 at 12:43 UTC ( [id://327893]=perlquestion: print w/replies, xml ) Need Help??

MysticFallout has asked for the wisdom of the Perl Monks concerning the following question:

In JavaScript there is a routine (if that is what they are called) like this.

$something = ($hmm == "")?"some":"thing";

I'm sure there is something like this in perl, but I cant find anything really. I cant even remember what this is called.

Thank you for any and all help.
Steven

Replies are listed 'Best First'.
Re: alternative to if statements
by broquaint (Abbot) on Feb 10, 2004 at 12:47 UTC
Re: alternative to if statements
by Abigail-II (Bishop) on Feb 10, 2004 at 12:56 UTC
    Perl has something similar to that. And strange as it is, it has the same syntax. Would you believe it is because they copied it from another well known language? Like all operators, it's documented in man perlop. It's listed as ?:, and discussed under the name conditional operator.

    Abigail

      Thank you all for your replies, it is very much apreciated! I do have on question:

      I do not have perl installed on my computer, and my webhost is running a winnt server under IIS, can I still access this man perlop?

        You could of course always download the Perl tarball, and extract the manual pages.

        Keeping the manual pages within easy reach one the smartests things you can do as a Perl programmer. It's in between breathing and keeping a supply of ice-cold Coca Cola.

        Abigail

Re: alternative to if statements
by Old_Gray_Bear (Bishop) on Feb 10, 2004 at 12:50 UTC
    It's called the 'ternary' or 'hook' conditional operator.

    ----
    I Go Back to Sleep, Now.

    OGB

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 20:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found