Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

(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")

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://34954]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2018-06-23 13:10 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.