Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: mysterious error of read function in solaris

by JavaFan (Canon)
on Jan 19, 2012 at 14:27 UTC ( #948785=note: print w/ replies, xml ) Need Help??


in reply to mysterious error of read function in solaris

You're dying whenever $! is a non-false value. But $! having a non-false value is not an indication anything is wrong. Check the system call, only if that is false, $! will have a useful value. In all other cases, you may not rely on $! having a sensible value.

In this, my bet is that Solaris sets errno to 13 during one of the system calls that are being made. And an OS is free to do so, the 13 only needs to signal something if the call fails (which it won't, because if the read fails, you aren't testing $!).


Comment on Re: mysterious error of read function in solaris
Select or Download Code
Re^2: mysterious error of read function in solaris
by david2008 (Scribe) on Jan 19, 2012 at 15:39 UTC
    Which variable should i check if read fails?
      Whatever variable you put the return value of read in. From perldoc -f read
      Returns the number of characters actually read, 0 at end of file, or undef if there was an error (in the latter case $! is also set).
      So, you'd do something like:
      my $r; while ($r = read ...) { ... do stuff here ... } die "read failed: $!" unless defined $r;
      I guess since 5.10, you could also write:
      while (read(...) // die "read failed: $!") { ... do stuff here ... }
      but I don't think I would want to recommend that.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-12-28 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls