#!/usr/local/bin/perl -w use strict; use warnings; my $dumpfile = "Data1.txt"; # write the name of the input file my $boltons = "Data2.txt"; my $resdir = "errors"; # directory where will be saved the files with the unused packs my %dump_packs; my @pack; my $bolt; my %exist; my @tmp; my $i=0; if (! -d $resdir) { mkdir($resdir) or die("Could not create result directory $resdir\n"); } open (my $in, '<', $dumpfile) or die "Could not open $dumpfile: $!\n"; while (<$in>) { my @tmp=split(/,/, $_, -1); my $line= $tmp[0];# the number related to the name push @{$dump_packs{$tmp[2]}}, $line ; # hash: key: name, value: number } close $in; for my $key (sort keys %dump_packs) { # write the name and occurency in a new file @pack=$key; open(my $out, '>', "$resdir/ ${dumpfile}_dump.txt") or die $!; print $out join('', $key); # key and occurency ??? close $out; } open (my $in2, '<', $boltons) or die "Could not open $dumpfile: $!\n"; while (<$in2>) { # find the missing dump_packs keys comparing dump_packs keys with the records into Data2.txt chomp($_); my $bolt = $_ ; for ($i = 0; $i <= $#pack; $i++) { if($bolt =~ /$pack[$i]/) { $exist{$pack[$i]} += 1;} # exist else { $exist{$pack[$i]} += 0;} # not exist } for my $key (sort keys %exist){ # write the unexisting names from the Data1.txt with the related numbers in a new error file: packs not in the list if ($exist{$key}==0){ my $index=$key; for my $key (sort keys %dump_packs){ if ($key=~ /$index/){ open(my $out, '>', "$resdir/ ${dumpfile}_packs_notlist.txt") or die $!; { print $out join(',', @{$dump_packs{$key}}); close $out; } } } } } } close $in2;