#!/usr/bin/perl
use strict;
#----------------
# Hash Definition
#----------------
my %HoA;
my @name;
#--------------------
# Subroutine
#--------------------
sub comp_file{
my ($FILE1, $FILE2) = @_;
open (R, $FILE1) or die ("Can't open file $FILE1");
foreach my $FP1(<R>){
chomp($FP1);
my ($k, $l) = split(/\s+/,$FP1);
push @{$HoA{'$FP1'}{$k}},$l;
}
close (R);
open (P, $FILE2) or die ("Can't open file $FILE2");
foreach my $FP2(<P>){
chomp($FP2);
my ($k, $l) = split(/\s+/,$FP2);
push @{$HoA{'$FP2'}{$k}},$l;
}
close (P);
foreach my $key(keys %{$HoA{'$FP1'}}){
if (!exists $HoA{'$FP2'}{$key}){
foreach my $last(@{$HoA{'$FP1'}{$key}}){
push (@name,"$key$last");
}
}
}
print "$_\n" for (sort @name);
}
############MAIN MENU####################################
# Pre-check Condition
# if the input doesn't contain two(2) files, return help
# USAGE: check.pl FILE1 FILE2
#########################################################
if ($#ARGV != 1){
print "USAGE: $0 <FILE1> <FILE2> \n";
exit;
}
else {
my ($FILE1, $FILE2)= @ARGV;
&comp_file($FILE1, $FILE2);
}
##RESULT DATA#####
#a2.txt
#a4.txt
#a5.txt
#a6.txt
#a8.txt
#a_index.txt
OK I get it, you want to physically remove the files, so then grep should list the files that are common to the folder and the file so -v should be left out.