我的问题很简单.但无法解决执行我的Perl脚本后收到的“不适当的I / O控制操作”错误.
#!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"; }
任何想法,我做错了什么?我在Windows7上的ActiveState perl上运行此脚本
解决方法
我怀疑你的脚本是打印$的值!通过一个开放的&&死!或开放或死亡$!;打印$!;.
这是一个在Windows上重现相同问题的最小脚本:
C:\> perl -e "open my $fh,'file_that_opens' && die $!" Inappropriate I/O control operation
以下是* nix上发生的事情:
$perl -e 'open my $fh,"<","file_that_opens" && die $!' Inappropriate ioctl for device
记录此行为
根据perldoc perlvar
,$!只有在失败的情况下才有意义.调用open时,它会为$!设置一个值,但该值仅在open未成功时才有用:
…
$!
is meaningful only immediately after a failure:06002
Here,meaningless means that
$!
may be unrelated to the outcome of
theopen()
operator.