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

never used references to an array, any advice?
  • Comment on Re^2: How can I merge data using a hash?

Replies are listed 'Best First'.
Re^3: How can I merge data using a hash?
by pg (Canon) on Oct 10, 2004 at 22:15 UTC

    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;
Re^3: How can I merge data using a hash?
by Roy Johnson (Monsignor) on Oct 11, 2004 at 15:41 UTC
    perldoc perlreftut

    Caution: Contents may have been coded under pressure.