in reply to setting values in anonymous hash
You can use map on the expanded hash to alter any undef'ined value to be equal to '' instead. As you cannot use undef as a hash key (it is turned into a string, so becomes '' (although a literal 'undef' becomes the string 'undef')) then this won't hurt any of the keys:
%new_hash = map {defined($_) ? $_ : ''} %{$ref2};For your example you could replace all the code above with something along the lines of:
$rh_foo = {a=>undef, b=>'b_value', c=>undef, e=>'e_value'}; push @foo, { map {defined($_) ? $_ : ''} %{$rh_foo} }; foreach (keys %{$foo[0]}) { print "$_ => ${$foo[0]}{$_}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: setting values in anonymous hash
by Dominus (Parson) on Nov 28, 2000 at 21:45 UTC | |
by merlyn (Sage) on Nov 28, 2000 at 21:53 UTC | |
by Dominus (Parson) on Nov 28, 2000 at 22:37 UTC | |
by extremely (Priest) on Nov 29, 2000 at 06:36 UTC | |
by mwp (Hermit) on Dec 18, 2000 at 15:15 UTC | |
by chipmunk (Parson) on Dec 18, 2000 at 19:43 UTC | |
by snax (Hermit) on Nov 28, 2000 at 22:03 UTC | |
by Dominus (Parson) on Nov 28, 2000 at 22:27 UTC | |
by snax (Hermit) on Nov 28, 2000 at 22:40 UTC | |
by Dominus (Parson) on Nov 28, 2000 at 23:26 UTC | |
|