in reply to Hash Question

I think this might work for you, basicly all it does is takes two hashes with the same keys but different values and then merges them into one hash with the same keys but values as arrayref's of the values of the other two hashes :)
use strict; my(%hash1) = ( 'foo' => 'bar', 'bleh' => 'qwer', 'lala' => 'asdf' ); my(%hash2) = ( 'foo' => 'bvcx', 'bleh' => 'lkjh', 'lala' => 'iopj' ); my(%hash3) = map { $_ => [$hash1{$_}] } keys(%hash1); map { push(@{$hash3{$_}},$hash2{$_}); } keys(%hash2); foreach (keys(%hash3)) { print "$_ is\n"; map { print "\t$_\n"; } @{$hash3{$_}}; }



lindex
/****************************/ jason@gost.net, wh@ckz.org http://jason.gost.net /*****************************/

Replies are listed 'Best First'.
RE: Re: Hash Question
by chromatic (Archbishop) on Oct 06, 2000 at 08:28 UTC
    This could be made into one line, but it's too late at night to do the formatting change:
    foreach my $key (keys %hash1) { $hash1{$key} = [ defined $hash2{$key} ? ($hash1{$key}, $hash2{$key}) : $hash1{$key} ]; }
    That could be made to go into a different hash, if that's your thing.
      better yet :) (at least I think this will work)
      $hash3 = map { $_ => [ $hash1{$_}, $hash2{$_} ] } keys(%hash1);
      p.s. vroom should allow us to customize the size of our text fields... I work on a 20 inch monitor with I.E in fullscreen mode :)


      lindex
      /****************************/ jason@gost.net, wh@ckz.org http://jason.gost.net /*****************************/