Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: forgoing explicit file close

by sundialsvc4 (Abbot)
on Aug 23, 2015 at 15:13 UTC ( #1139583=note: print w/replies, xml ) Need Help??

in reply to forgoing explicit file close

Agree .. agree .. agree .. upvote .. upvote .. upvote.

The entire process of handling a file is fraught with potential errors:   opening it, read/write, seek, and close..   Your code therefore needs to explicitly do all of it, and to explicitly check for errors.   You might have “successfully written” a bunch of data to the file, not realizing that it’s still in Perl’s buffers, when the file has gone away and the problem will not be detected until Perl attempts to write those buffers (e.g. at close time).   Even if a warning message is produced, that is not something that your program can intercept and react to ... so, that’s not good enough.   Your program will behave “mysteriously,” and that’s what causes the pager to go-off in the middle of the night or when you are having ... well, anyway ...   ;-)

Never let Perl do such things “by default.”   Code like that only works when it works.

Replies are listed 'Best First'.
Re^2:forgoing explicit file close
by 1nickt (Abbot) on Aug 23, 2015 at 15:24 UTC

    Since it's Sunday ...

    From Psycho Killer, Talking Heads, © David Byrne 1977:

    You're talking a lot, but you're not saying anything. When I have nothing to say, my lips are sealed. Say something once, why say it again?
    The way forward always starts with a minimal test.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2020-09-30 23:20 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (171 votes). Check out past polls.