in reply to How can I merge data using a hash?

As for data structure, how about hash of array ref. The hash key is your complex number. Each array ref contains two numbers, one from file1, and one from file2.

Replies are listed 'Best First'.
Re^2: How can I merge data using a hash?
by Anonymous Monk on Oct 10, 2004 at 22:13 UTC
    never used references to an array, any advice?

      Some code: (you may have to refine a bit, do things like output formating, sorting etc.)

      use Data::Dumper; use strict; use warnings; my $hash; open(FILE, "<", "file1.txt"); while (<FILE>) { my ($k, $v) = split " "; $hash->{$k}->[0] = $v; } close FILE; open(FILE, "<", "file2.txt"); while (<FILE>) { my ($v, $k) = split " "; $k = /(complex\.\d+)/; $hash->{$1}->[1] = $v; } close FILE; print Dumper($hash); open (OUT, ">", "out.txt"); for my $key (keys(%$hash)) { print OUT $key . " " . $hash->{$key}->[0] . " " . $hash->{$key}->[ +1] . "\n"; } close OUT;
      perldoc perlreftut

      Caution: Contents may have been coded under pressure.