Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Things every perl programmer should know?

by Mr. Muskrat (Abbot)
on Jun 04, 2003 at 14:25 UTC ( #263002=note: print w/ replies, xml ) Need Help??


in reply to Things every perl programmer should know?

Every perl programmer should understand the conditional operator, or the ternary "?:". It works much like an if-then-else statement. I'll give two examples of usage.

if ($condition) { $foo = $bar; } else { $foo = $baz; }
becomes:
$foo = $condition ? $bar : $baz;

if ($condition) { $baz = $foo; } else { $bar = $foo; }
becomes:
($condition ? $bar : $baz) = $foo;

Be careful with the second one, both $bar and $baz must be valid lvalues! That means that you must be able to assign values to them.

Updated to meet the expectations of the updated OP.


Comment on Re: Things every perl programmer should know?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2014-07-25 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (172 votes), past polls