alongwor has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I have a very strange problem that I hope you can help me with. I have the following code to open a text file.
if ($status_hash {exit_code} == 0) { open (EXECUTE_LIST, $execute_file); if ($! ne "") { $status_hash {exit_code} = 51; $status_hash {exit_message} = "The file $execute_file did not +exist and we are in the execute function.\n\t\tvar \$! = $!"; }
When I run the code on one machine I get the following error from the $! variable
Inappropriate ioctl for device
On the second machine, this runs fine without such an error message.
Anyone got any ideas that may help
Thanks in advance,

Replies are listed 'Best First'.
Re: Inappropriate ioctl for device
by liz (Monsignor) on Oct 16, 2003 at 13:41 UTC
    You're checking $! even if there was no error!

    Check out open and perlvar. From perlvar:

    if (open(FH, $filename)) { # Here $! is meaningless. ... } else { # ONLY here is $! meaningful. ... # Already here $! might be meaningless. }

    Liz

Re: Inappropriate ioctl for device
by Abigail-II (Bishop) on Oct 16, 2003 at 13:51 UTC
    $! will only contain a meaningful value after *failure* of a system related operation. If the operation was successful, $! may, or may not be set - and if set, it could be anything. Use the return value of open to determine whether the action succeeded, not the value of $!.

    Abigail