use Text::Diff;
my $count;
our $stats2 = 0;
for($count = 0; $count <= 1000; $count++){
my $data_dir="archive/oswiostat/oracleapps.*dat";
my $data_file= `ls -t $data_dir | head -1`;
chomp($data_file);
while(defined($data_file)){
print $data_file;
open (DAT,$data_file) || die("Could not open file! $!");
my @stats1 = stat $data_file;
my @raw_data=<DAT>;
close(DAT);
print "Stats1 is :$stats1[9]\n";
sleep(5);
print "Checking $stats1[9] equals $stats2\n";
if(chomp($stats1[9]) != chomp($stats2)){
print "I am here";
my @diff = diff \@raw_data, $data_file, { STYLE => "Context" };
print @diff || die ("Didn't see any updates $!");
}
$stats2 = $stats1[9];
print "Stat2: $stats2\n";
}
}
Output
[oracle@oracleapps osw]$ perl client_socket1.pl
archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1900.datStats1 is :1340925244
Checking 1340925244 equals 0
Stat2: 1340925244
archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1900.datStats1 is :1340925298
Checking 1340925298 equals 1340925244
Stat2: 1340925298
archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1900.datStats1 is :1340925304
Checking 1340925304 equals 1340925298
Stat2: 1340925304
archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1900.datStats1 is :1340925304
Checking 1340925304 equals 1340925304
Stat2: 1340925304
archive/oswiostat/oracleapps.localdomain_iostat_12.06.28.1900.datStats1 is :1340925304
As show in the output when @stats1[9] is not equal to $stats2 it should go into the if loop and print “I am here” but it is not working that way. Can you please identify the problem.
chomp()modifies a string as a side-effect and returns the linefeed it deleted from a string, not the modified string. You likely want to write