Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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: (3)
As of 2015-07-04 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls