my question is rather simple,. but can't resolve "Inappropriate I/O control operation" error which I'm receiving after execution of my Perl script.
#!C:/Perl/bin/perl.exe -w
use strict;
my $file = "D:/file.csv";
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
while (my $line = <$data>) {
chomp $line;
my @fields = split "," , $line;
print $fields[1]."\n";
}
any idea, what I'm doing wrong? I'm running this script on ActiveState perl on windows7
My suspicion is that your script is printing the value of $!
through an open && die $!
or open or die $!; print $!;
.
Here is a minimal script that reproduces the same issue on Windows:
C:\> perl -e "open my $fh, '<', 'file_that_opens' && die $!"
Inappropriate I/O control operation
And here is what happens on *nix:
$ perl -e 'open my $fh, "<", "file_that_opens" && die $!'
Inappropriate ioctl for device
According to perldoc perlvar
, $!
is only meaningful in the event of a failure. When open
is called, it sets a value for $!
, but the value is only useful if the open
did not succeed:
...
$!
is meaningful only immediately after a failure:if (open my $fh, "<", $filename) { # Here $! is meaningless. ... } else { # ONLY here is $! meaningful. ... # Already here $! might be meaningless. } # Since here we might have either success or failure, # $! is meaningless.
Here, meaningless means that
$!
may be unrelated to the outcome of theopen()
operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With