in reply to How can I merge data using a hash?
use strict; my @file1 = ( "complex.1\t1.356\n", "complex.2\t1.879\n", ); my @file2 = ( "12.02\t/home/complex.2out\n", "10.25\t/home/complex.1out\n", ); my (%hash, $ref, $values); chomp(@file1); chomp(@file2); foreach (@file1) { $_ =~ /^complex\.(\d+)\t([\d\.]+)$/; $hash{$1}->[0] = $2; } foreach (@file2) { $_ =~ /^([\d\.]+)\t\/home\/complex.(\d+)out$/; $hash{$2}->[1] = $1; } foreach (sort {$a <=> $b} keys %hash) { $ref = $hash{$_}; $values = join("\t", @$ref); print "complex.$_\t$values\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I merge data using a hash?
by Anonymous Monk on Oct 10, 2004 at 23:00 UTC | |
by TedPride (Priest) on Oct 10, 2004 at 23:35 UTC |