I have a file soa.csv
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/diagnostics/config,0750
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/diagnostics/config/registration,0750
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uix2.jar,0640
There is another file soa2.csv
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/diagnostics/config/registration,0740
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/diagnostics/config/registration/OUI.xml,0740
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1,0750
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uix2.jar,0640
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uix3.jar,0640
I want to compare these 2 files. For this I am pushing the contents of both the files in 2 separate hashes. such that key is the filePath and value is the file permission after comma in the csv.
My algo is if key of hash1 is present in hash2,compare the value.If different,then print it in a file.
$changedPermissions="FilesWithChangedPermissions.dif";
unless(open FH3, '>>'.$changedPermissions) {
die "Unable to create $changedPermissions";
}
foreach my $key2 ( keys %hash2 ) {
next unless ( exists $hash1{$key2} );
my $val1 = join(",", sort @{ $hash1{$key2} });
my $val2 = join(",", sort @{ $hash2{$key2} });
if ($val1 eq $val2) {
print FH4 "$key2";
}
else {
print FH3 "$key2 $val1 $val2\n";
}
}
Please note I am using join because in future the csv file may contain other attributes like file Size etc. The content of FilesWithChangedPermissions.dif is:
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uix2tags.jar 0640 0640
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/diagnostics/config/registration/OUI.xml 0740 0740
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uix11.war 0640 0640
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uix2-install.zip 0640 0640
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1 0750 0750
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uixadfrt.jar 0640 0640
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uix2.jar 0640 0640
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/diagnostics/config/registration 0750 0740
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/modules/oracle.uix_11.1.1/uix2.jar 0640 0640
/net/slc06wmg/scratch/aime1/work/IDM/BASEDIR/IDMTOP/products/app/soa/diagnostics/config/registration 0750 0740
Thus,files with same file permissions is also getting printed in the output which is wrong.
Please help..I am new to perl..Any help will be appreciated!!