in reply to Re: Undef and Unitialized Issue
in thread Undef and Unitialized Issue
my $string_var = defined( $input_field ) || '';
This will set $string_var either to 1 or to "", no matter what $input_field was set to. Looking at the variable names, this is hardly what you want.
($string_var || '')
This evaluates to "" if $string_var is undef, 0, or "0". You don't want to change "0" or 0 to the empty string, do you?
Why don't you use the defined-or operator //? $string_var//'' evaluates to "" only if $string_var is "" or undef. 0 and "0" are not changed.
Ancient perl versions have no defined-or-operator, so you have to resort to something like $never_undef=defined($perhaps_undef) ? $perhaps_undef : ''; for code that is expected to work with ancient perl verisons.
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Undef and Unitialized Issue
by boftx (Deacon) on Apr 06, 2015 at 15:18 UTC |