Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Inappropriate I/O control operation (Updated)

by 1nickt (Canon)
on Sep 26, 2017 at 15:25 UTC ( [id://1200119]=note: print w/replies, xml ) Need Help??


in reply to Inappropriate I/O control operation

Update: OIC, you are using $! in your print statement. I missed that. Why? What are you trying to print?

As explained below by dave_the_m, you use $! after an error when it might hold a message about the error (if whatever encountered the error is nice enough to tell you). That's why I used it to check the return value of your file open call, which is where I assumed the error was coming from: it will tell you if you've made a typo in the path and the file does not exist, for example. In your case it is printing something unuseful because you're not using it the right way. What did you want to print there?

Original reply:


Try adding error checking and debugging to your program:

open(my $in, '<', $fn) or die "Died opening file: $fn error: $!";
Also note the three argument form of open, which is safer.

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Inappropriate I/O control operation
by cormanaz (Deacon) on Sep 26, 2017 at 17:02 UTC
    Thanks for the suggestion. I did print $! in the statement underneath the open in the original script. But I modified the open per your suggestion. It didn't die on any of the opens but still gave the error in $! in the following line. Then I tried reading and printing the first line of each file and it worked. Strange.
      $! is only meaningful after an error. Its value after a successful open is unspecified and could be anything.

      Dave.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1200119]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-18 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found