Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

(tye)Re: ((Conditional, Ternary Operator)) Specifying default and non-default

by tye (Cardinal)
on Oct 02, 2000 at 22:49 UTC ( #34954=note: print w/ replies, xml ) Need Help??


in reply to ((Conditional, Ternary Operator)) Specifying default and non-default values

If you already have the very useful def in your toolbag:

sub def { $_[0]= def($_[1],"") if ! defined $_[0]; return $_[0]; }
then you can do this as:
$ext{index} = 'pod'; for my $pod ( qw( HostCycle Instinet index ) ) { system "pod2html $pod" . def($ext{$pod},".pm") . " > $pod.html"; }

def (short for "define" which would be too easy to confuse with "defined") is useful for avoiding warnings. You can use it like || as above or like ||=. It differs from these two operators in that it triggers on definedness rather than truthness.

Note that def is so useful that even def uses it. ;)

        - tye (but my friends call me "Tye")


Comment on (tye)Re: ((Conditional, Ternary Operator)) Specifying default and non-default
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-12-22 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls