George P. said:

> On Mon, 3 Mar 2003, Scott R. Godin wrote:
>
>>
>> my @scores;
>> my @files = glob "/home/johann/smail/Spam/*";
>> foreach my $file (@files) {
>>         open(IN, "<", $file) or die "Cannot open file $file: $!";
>>         while (<IN>) {
>>                 next unless /^Subject:/;
>>                 push @scores, $_;
>>                 last; # found what we need, no need to go further with
>> this file
>>         }
>>         close IN or die "Cannot close filehandle for $file: $!";
>> }
>
> I noticed that you've said
> "open () or die()"
> and
> "close() or die()"
>
> If open fails, the program will kill itself, so the close function
> will never be called.
> Therefore there is no need to say "close() or die()"

I don't follow this logic.

If you are reminding us that since the file manipulation is within a loop
the open automatically closes the previous file and therefore you can get
away without doing an explicit close, then this is quite correct.  But I
don't think this is what you are saying.

If you are saying that because the file was successfully opened the close
cannot fail, then this is not correct.  Now, it might not fail very often,
and even when it does you might not care, but then again you might, and I
normally do.  If something goes wrong, I like to know about it.

> You've done it thrice in this email, so I'm presuming
> that it's a habitual thing.

And a good habit, IMHO.

> Putting it won't hurt, but it's not useful either.

I hope to have convinced you otherwise.

> Just thought I should point it out :)

Me too :)

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to