in reply to Re: Merge the difference between two files and save it on the first file. Also update the first file with info in second file.
in thread Merge the difference between two files and save it on the first file. Also update the first file with info in second file.
This is wrong. For example for the two given input files, your code gives the following output:
Output:%hash = map {$_ => 1} <DATA>; print for (sort keys %hash); __DATA__ A=hello B=world B=planet C=universe
A=hello B=planet B=world C=universe
... but the expected output is
A=hello B=planet C=universe
The input data is basically a two-column input and the keys are in the first column. The hash approach in general is correct, but you need to use the stuff left of the equal sign as key and the rest (or the whole line) as value:
use strict; my %hash = map {/^(.*)=/ or die "Malformed input: $_"; $1 => $_} <DATA +>; print for (sort values %hash); __DATA__ A=hello B=world B=planet C=universe
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Merge the difference between two files and save it on the first file. Also update the first file with info in second file.
by Lennotoecom (Pilgrim) on Oct 11, 2013 at 09:01 UTC |