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

Re: uninitialized value

by count0 (Friar)
on Jan 22, 2002 at 23:49 UTC ( #140717=note: print w/ replies, xml ) Need Help??


in reply to uninitialized value

As a preventative measure, this is a good rule of thumb to follow:
Whenever you aren't sure if a variable has been assigned a value, give it one explicitly =)

The || operator is very useful here.
Examples:

my $variable = $some_unknown_input || 'default'; my $foo = (defined $input ? $input : '');
In the first example, if $some_unknown_input is not a true value, $variable will be assigned 'default'.
In the second example, if $input is undefined (note this is not necessarily the same as being non-true, as in the first example), it is assigned an empty string.


Comment on Re: uninitialized value
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-11-22 10:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (121 votes), past polls