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:
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.
Whenever you aren't sure if a variable has been assigned a value, give it one explicitly =)
The || operator is very useful here.
Examples:
In the first example, if $some_unknown_input is not a true value, $variable will be assigned 'default'.my $variable = $some_unknown_input || 'default'; my $foo = (defined $input ? $input : '');
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.
|
---|
In Section
Seekers of Perl Wisdom