This is so we can dump it using data::dumper.
And the backslashes got lost on the post.
#!/usr/bin/perl -W
use strict;
use Data::Dumper;
# Usage: year_pri.pl 3 year_1.txt year_2.txt year_3.txt input_data.txt
# ###### Note the stupid 3 to tell it 3 files to follow, I wasn't showing him
# the getopts lib yet.
my $file_count = shift;
my $bug = 1;
my @pri_files;
while ($file_count--){
my $file = shift;
push(@pri_files, $file);
}
my %priority_rec;
foreach my $priority (@pri_files){
my ($tmp) = read_file($priority);
$priority_rec{$priority} = $tmp;
}
my %save_records;
while (<>){
my $in_rec = $_;
#"1990118STTSKYJH","BA","INH_ALL-PNCOA3-2011|Work|51207","LAST","FIRST","","","","PATTERSON & KELLY PA","",
if (/|(d+)"/){
my $id = $1;
YEAR_LOOP:
foreach my $priority (@pri_files){
if (defined($priority_rec{$priority}->{$id})){
push (@{$save_records{$priority}},$in_rec);
last YEAR_LOOP;
}
}
} #end if we got a match for the id
else{
die "Cannot get id from: [$_]n";
}
}
foreach my $priority (@pri_files){
print @{$save_records{$priority}};
}
exit (0);
sub read_file {
my $file = shift;
my %ret;
open (IN, $file) or die "Can't open $file for read - $!n";
while (<IN>){
my (@rec) = split(/t/, $_, 2);
$ret{$rec[0]}++;
}
close(IN);
return(%ret);
}