[TroubleShooting]Inappropriate I/O control operation

There's more than one way to do it!
https://metacpan.org http://perlmonks.org
头像
523066680
Administrator
Administrator
帖子: 340
注册时间: 2016年07月19日 12:14
拥有现金: 锁定
储蓄: 锁定
Has thanked: 30 times
Been thanked: 27 times
联系:

[TroubleShooting]Inappropriate I/O control operation

帖子 #1 523066680 » 2017年05月11日 14:52

触发条件:
Code: [全选] [展开/收缩] [Download] (Untitled.pl)
  1. open my $WRT, ">:utf8", "b.txt" or die "$!";
  2. print $!;
  3. 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.

Code: [全选] [展开/收缩] [Download] (Untitled.pl)
  1. #!C:/Perl/bin/perl.exe -w
  2. use strict;
  3.  
  4. my $file = "D:/file.csv";
  5. open(my $data, '<', $file) or die "Could not open '$file' $!\n";
  6. while (my $line = <$data>) {
  7.     chomp $line;
  8.     my @fields = split "," , $line;
  9.     print $fields[1]."\n";
  10. }

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:

Code: [全选] [展开/收缩] [Download] (Untitled.pl)
  1. if (open my $fh, "<", $filename) {
  2.                   # Here $! is meaningless.
  3.         ...
  4.     }
  5.     else {        # ONLY here is $! meaningful.
  6.         ...       # Already here $! might be meaningless.
  7.     }
  8.     # Since here we might have either success or failure,
  9.     # $! is meaningless.


Here, meaningless means that $! may be unrelated to the outcome of the open() operator.

回到 “Perl”

在线用户

用户浏览此论坛: 没有注册用户 和 1 访客