触发条件:
open my $WRT, ">:utf8", "b.txt" or die "$!";
print $!;
close $WRT;
Inappropriate I/O control operation
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
===========================================================================
This behavior is documented
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 the open() operator.