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