in reply to combining 2 files with a comon field
This is assuming the files have the same amount of lines:
Reads in one line from each file, extracts the column values using map and a regex, and then prints out a new line containing both column values, plus a header made from $.use IO::File; $f1 = new IO::File "< file1"; $f2 = new IO::File "< file2"; $f3 = new IO::File "> file3"; while (my ($c1, $c2) = map { m/^.*?\|(.*)\|$/ } ($f1->getline, $f2->ge +tline)) { print $f3 "A$.|$c1|$c2|\n"; last if eof; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: combining 2 files with a comon field
by jhourcle (Prior) on May 18, 2005 at 13:57 UTC |
In Section
Seekers of Perl Wisdom