in reply to Re: setting values in anonymous hash
in thread setting values in anonymous hash
> why wouldn't this work:It doesn't work because if $v was "hello", then you have just scrubbed it out and replaced it with the empty string.
> $ref2->{$k} = '' if $v == undef;
You should never compare anything for equality with undef, because 0 == undef is true, and "fish" == undef is also true. This is because undef behaves like 0 in a numeric context, and so do most strings. Even "" eq undef is true, which probably is not what you want.
The only way to check to see if something is undef is to use the defined operator:
$ref2->{$k} = '' if not defined $v;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: setting values in anonymous hash
by snax (Hermit) on Nov 28, 2000 at 19:55 UTC |