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.
becomes:if ($condition) { $foo = $bar; } else { $foo = $baz; }
$foo = $condition ? $bar : $baz;
becomes:if ($condition) { $baz = $foo; } else { $bar = $foo; }
($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.
In Section
Meditations