I see the contents of file deleted after perl grep, any reason/fix? I need to take decision if grep is success or not.
open my $fh, "<", $file or die "can't read open '$file': $OS_ERROR";
$start_sync=0;
if (grep{/PATTERN/} <$fh>){
print "word found\n";
$start_sync=1;
}
else{
print "word not found\n";
$start_sync=0;
}
my @lines = <$fh>;
close $fh or die "can't read close '$file': $OS_ERROR";
if($start_sync==1) {edit the same file}
While the grep itself is working, the contents of the file is blanked/deleted after the grep. Without the grep, this deletion doesnt happen. Wondering what causes the contents to be blanked out.