troubleshooting Question

Logic not working in the perl script

Avatar of new_perl_user
new_perl_user asked on
Perl
6 Comments1 Solution409 ViewsLast Modified:
Hi, Below is the perl script which compares data between two files. If data in file 1 exsists in file2  fine, else if not exsists it should print the id's that are missing  from file 2.

Issue: It is comparing file1 and file2  and also printing data not found, if they don't exist in file1 but it has to always print not found from file2.

Can anyone pls help me where I am doing the mistake.

#!/usr/local/bin/perl
use strict;
use warnings;

my $date = localtime(time()-48*60*60);
substr($date, 11, 9) = "";

print"$date\n";

my($sec, $min, $hour, $mday, $mon, $year) = localtime;

my $logFilename = sprintf("sync_DB_%d%02d%02d.txt", 1900+$year, $mon+1, $mday, $hour, $min, $sec);

open(LOG, ">/usr/hlm/qa/Scripts/nhl/STATS/LOGS/$logFilename");

open IN, '</usr/hlm/qa/Scripts/nhl/STATS/LOGS/DB/Scanner_Stats.txt' or die "could not open out.txt: $!";

my %hash1 = map { chomp; $_ => 1 } <IN>;

close IN;

open IN, '</usr/hlm/qa/Scripts/nhl/STATS/LOGS/sync_Stats.txt' or die "could not open sample.txt: $!";

my %hash2;

@hash2{ map{/(\S+)/} <IN>}=();

close IN;

if($hash1{$key1} eq $hash2{$key2})
{
print LOG 'FOLDER Total = '.keys %hash1,"\n\n", 'Linux FOLDER2 Total  = '.keys %hash2,"\n\n";
print LOG "List of not found IDS : 
",(join"\n ",@id),"\n\n" if @id=grep!(exists $hash2{$_}&&exists $hash1{$_}),keys %hash1,
keys %hash2;
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros