Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The code I have does thisword decimal word decimal word decimal
This works fine. However the format of the input files has now changed so that there are extra words i.e.open F1,"F1.dat" or die "Can't open F1.dat: $!\n"; open F2,"F2.dat" or die "Can't open F2.dat: $!\n"; my (%hash1,%hash2); while (<F1>) { /(\w*) (\d*)/ ; $hash1{$1} = $2 ; } close F1; while (<F2>) { /(\w*) (\d*)/ ; $hash2{$1} = $2 ; } close F2; open MERGED,">merge.dat" or die "Can't open merge.dat:$!\n"; foreach (sort keys %hash2) { if (defined($hash1{$_})) { print MERGED "$_ $hash1{$_}\n" ; } else { print MERGED "$_ $hash2{$_}\n" ; } } close MERGED;
The first two fields of each record will always be of the format "word decimal", but there could be an indeterminent number of words after the decimal.word decimal word....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: file merge problem
by davorg (Chancellor) on Dec 09, 2005 at 12:51 UTC | |
by Anonymous Monk on Dec 09, 2005 at 13:17 UTC | |
|
Re: file merge problem
by Samy_rio (Vicar) on Dec 09, 2005 at 12:49 UTC | |
by Anonymous Monk on Dec 09, 2005 at 13:14 UTC | |
by ptum (Priest) on Dec 09, 2005 at 14:25 UTC | |
by Anonymous Monk on Dec 09, 2005 at 14:56 UTC | |
by ptum (Priest) on Dec 09, 2005 at 17:24 UTC | |
|
Re: file merge problem
by injunjoel (Priest) on Dec 09, 2005 at 22:41 UTC | |
|
Re: file merge problem
by Delusional (Beadle) on Dec 09, 2005 at 13:06 UTC | |
|
Re: file merge problem
by thundergnat (Deacon) on Dec 09, 2005 at 14:52 UTC |