Perl grep inside of an if clause?

martinthurn

New member
You should not try to write such terse code. What is the benefit? See, you just get yourself into trouble.

If the file is not too large, just read the whole file (that's what you're doing anyway, just without an explicit variable):

local $/ = undef;
my $sContents = <IN>;
if ($sContents =~ m/Export terminated/)
...
 
I have the following in my perl script to run on Windows servers:
IN and OUT being part of the open commands to open the files.

if (grep(/Export terminated successfully without warnings./, <IN>)) {
print "SUCCESS IT WORKS";
} else {
$errorfound="T";
print OUT "The export has not finished yet\n";
}

The problem is that when I run the script it always goes into the else statement even if the file has the 'Export terminated successfully without warnings.' line. Am I botching what I am passing into grep (i.e. the regex) or is my logic wrong on the if statement? Thanks.
 
Back
Top