in reply to Error reading line from file: Operation timed out
if (!$line || $!) {
There's no guarantee that $! is unset at the moment you test it. It might be propagated from elsewhere and might not mean anything here. See perlvar:
$!If used numerically, yields the current value of the C "errno" variable, or in other words, if a system or library call fails, it sets this variable. This means that the value of $! is meaningful only immediately after a failure:(emphasis mine)In the above meaningless stands for anything: zero, non-zero, "undef". A successful system or library call does not set the variable to zero.if (open(FH, $filename)) { # Here $! is meaningless. ... } else { # ONLY here is $! meaningful. ... # Already here $! might be meaningless. } # Since here we might have either success or failure, # here $! is meaningless.
So you should test use $! immediately after a system call which failed i.e. didn't give the expected results, in your case, if open doesn't return a true value:
my $isOpen = open($handle, $templateLocation) or die "foo: $!";
Your readline might succeed, but that doesn't reset $! if it was set prior to the successful readline() call.
|
|---|