hypochrismutreefuzz has asked for the wisdom of the Perl Monks concerning the following question:
How is the best way to initialize a hash_ref?
my $hash_ref = { hack => slash, frobozz => portrait, candle => lit, }; my @keys = keys %$hash_ref; my $hash_copy = {};
Now say we want $hash_copy to contain a copy of all the information in $hash_ref. Which of these is preferable?
@{ $hash_copy } { @keys } = @{ $hash_ref } { @keys }; $hash_copy->{$_} = $hash_ref->{$_} for @keys;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash Ref Initialization
by eric256 (Parson) on Dec 10, 2007 at 20:36 UTC | |
|
Re: Hash Ref Initialization
by mwah (Hermit) on Dec 10, 2007 at 20:51 UTC | |
|
Re: Hash Ref Initialization
by Roy Johnson (Monsignor) on Dec 10, 2007 at 20:50 UTC |