On 11-06-07 12:48 PM, Brian F. Yulga wrote:
Even though your way is short and concise, perhaps it's safer to check each key before assignment?
Or you could make the new hash a hash of arrays: #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; # Make Data::Dumper pretty $Data::Dumper::Sortkeys = 1; $Data::Dumper::Indent = 1; # Set maximum depth for Data::Dumper, zero means unlimited local $Data::Dumper::Maxdepth = 0; my $hash_ref_1 = { a => 1, b => 2, }; my $hash_ref_2 = { a => 3, c => 4, }; my $new_hash_ref = {}; load_hash( $new_hash_ref, $hash_ref_1 ); load_hash( $new_hash_ref, $hash_ref_2 ); print Dumper $new_hash_ref; # -------------------------------------- # Name: load_hash # Usage: load_hash( \%new_hash_ref, $hash_ref ); # Purpose: push the values of the second hash onto the first # Parameters: \%new_hash_ref -- where they go # $hash_ref -- where they're from # Returns: (none) # sub load_hash { my $new_hash_ref = shift @_; my $hash_ref = shift @_; for my $key ( keys %$hash_ref ){ push @{ $new_hash_ref->{$key} }, $hash_ref->{$key}; } return; } -- Just my 0.00000002 million dollars worth, Shawn Confusion is the first step of understanding. Programming is as much about organization and communication as it is about coding. The secret to great software: Fail early & often. Eliminate software piracy: use only FLOSS. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/