in reply to Re: foreach not working as I expected
in thread foreach not working as I expected
And don't forget to close the file when done.
If you're going to check the status of the close, that's one thing (and it should be done more), but it's not really necessary if you're opening the same filehandle immediately. Here's a more paranoid version of the loop where I'd close:
for my $file (<*.txt>) { open my $add, '>>', $file or die "Can't open file: $!\n"; print $add $txt; close $add or die "Can't close file: $!\n"; }
Update: Oh yeah, in a long-running program that can be a problem. That's why I prefer to localize the glob or to use lexical filehandles. :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: foreach not working as I expected
by pfaut (Priest) on Dec 18, 2002 at 18:15 UTC | |
|
Re: Re: Re: foreach not working as I expected
by mce (Curate) on Dec 19, 2002 at 15:25 UTC |