Well, I did say it was untested. ;-)
Do make the same changes to the %file2 hash statement, too, in the original code. This clears the | and newline at the end of each file line before splitting, and limits the split to two parts. Hope that helps!# my %file1 = map { split '\|', $_ } <FILE1>; my %file1 = map { chomp && s/\|$//g && split '\|', $_, 2 } <FILE1>;
BTW, this is a good example of how using warnings and strict point out where the bugs are. I knew what the issue was as soon as I saw those two warning statements. ;-) Also, make sure that your file is well-formed: that is, it ends with a newline, or you might get interesting results.
This should *not* be done in production without some better error control...
The Eightfold Path: 'use warnings;', 'use strict;', 'use diagnostics;', perltidy, CGI or CGI::Simple, try the CPAN first, big modules and small scripts, test first.
In reply to Re^3: combining 2 files with a comon field
by radiantmatrix
in thread combining 2 files with a comon field
by jjohhn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |