Incorrect I / O control

my question is pretty simple. but cannot resolve the "Inappropriate I / O Control" error that I get after running 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 am i doing wrong? I run this script in ActiveState perl on windows7

+4
source share
1 answer

I suspect your script is printing the value $!via open && die $!or open or die $!; print $!;.

The following is a minimal script that reproduces the same problem on Windows:

C:\> perl -e "open my $fh, '<', 'file_that_opens' && die $!"
Inappropriate I/O control operation

And this is what happens on * nix:

$ perl -e 'open my $fh, "<", "file_that_opens" && die $!'
Inappropriate ioctl for device

This behavior is documented.

perldoc perlvar, $! . open, $!, , open :

... $! :

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.

, $! open().

+5

All Articles