Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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

by tye (Sage)
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?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2015-11-26 00:20 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (693 votes), past polls