Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: close or die

by FoxtrotUniform (Prior)
on Nov 11, 2004 at 22:42 UTC ( #407207=note: print w/ replies, xml ) Need Help??


in reply to close or die
in thread Making an array out of each line in a file

Sorry for being pedant but we are opening files here, so - unless you mistype your file handle, - you can always close a filehandle. Or am I wrong?

No need to apologize for being pedantic :-). I can't think of a situation where close would fail on a plain old file on a local filesystem; for that, it's just habit. But networked filesystems, sockets, pipes, and so on can mess up close; besides, Always Check System Call Return Values is a good habit to get into.

--
Yours in pedantry,
F o x t r o t U n i f o r m

"Anything you put in comments is not tested and easily goes out of date." -- tye


Comment on Re: close or die
Select or Download Code
Re^2: close or die
by PerlingTheUK (Hermit) on Nov 11, 2004 at 23:09 UTC
    Thanks,
    I sometimes need some help with my English. Besides I think the original request was rather lacking to understand that
    my ( $a, $b, ... $z )
    is acutally an array. So it was my intention - and even though it was counter productive in the end - to avoid confucion of what is actually going on between open and close.
    BTW, my choice for reading a file into an array still is File::Slurp which was discussed quite exhaustively recently in a thread i just cannot find right now.

    Cheers,
    PerlingTheUK
      Just to be super-super pedantic: my ( $a, $b, ... $z )
      is a list, not an array :-)
Re^2: close or die
by Fletch (Chancellor) on Nov 12, 2004 at 00:50 UTC

    According to man 2 close (FreeBSD, OpenBSD and OS X) the two cases are:

    ERRORS Close() will fail if: [EBADF] D is not an active descriptor. [EINTR] An interrupt was received.

    </unecessarily complete information>

    But agreed, always checking the return value from system calls is good practice (just like you should always check your optics before testing your high powered laser when that jerk Kent's around . . . </Real Genius>).

    Update: Ooop, tilly is correct below. Perl's close is more akin to fclose(3) than close(2) and can return with errno of any of the errors from close(2) or fflush(3) (and fflush(3) in turn may set errno if an underlying write(2) failed).

      That's actually not complete information since Perl's close is more complicated than the corresponding C call. In particular when you close a file in Perl it also flushes data to the filehandle, which can fail if the filesystem is full.

      Would you like to get an error message when your file got truncated because the filesystem was full?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-12-22 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (113 votes), past polls