Hi Chas.,


Chas. Owens wrote:
On Tue, Nov 18, 2008 at 10:05, Raymond Wan <[EMAIL PROTECTED]> wrote:
Hi Lauri,

Good to hear -- if the file is small enough to be read in entirely, that is
what I would do.  If you need to add in another loop to output a third file,
then you can just add it in easily to make another pass.

One suggestion which makes no difference to your program and some people
might disagree with me is to move the "close" up so that you close the file
pointer as soon as you know you don't need it anymore.  I use to close it at
the end, but when my scripts became pages long, I sometimes forgot...  :-)
 And it minimizes the time that you keep it open.  But it won't make a big
difference for your script...just a suggestion.
snip

Perl closes all file handles at the end of the program, so the only
reasons to close file handles early are
1. the program doesn't end (it is a daemon)
2. you have a limited number of file handles in your environment (or
you consume an unreasonable amount)
3. a different program will need access to the file soon (a variation on 1)
4. you have unlink'ed the file and don't want it to continue to
consume space (at least on UNIX systems)

One of the nice things about lexical file handles is that they close
automagically when they are garbage collected (normally when they go
out of scope).



Yes, you are of course right. I close files because of (3) sometimes but usually for a reason 5 which some may not agree with -- just a habit to check what I've done. Like closing a door after you walk through. For the same reason, in other languages, I free memory even though I know it will be done for me. Just a habit...

So yes, it will be done for you...I'm glad the days of having to manage everything from initialization to destruction is behind us and something we do not have to worry about for some languages like Perl... :-)

Ray



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to