in reply to Opening files in a loop

To clarify, using a lexical file handle is as follows:
my $handle; open ($handle, $filename); ... close ($handle);
The advantage of lexicals is that you can use the same file handle (locally scoped) inside nested calls of a sub without collisions, and you can easily store the handle inside a data structure and retrieve it later.

Re: Three arguments for open vs two - is this really a major concern if you control all file paths yourself? Seems to me that you only really need to worry if the path contains user input, in which case tainting / parsing should do the trick. Can you explain how someone could do damage by accident rather than on purpose?

Replies are listed 'Best First'.
Re^2: Opening files in a loop
by chromatic (Archbishop) on Jun 04, 2005 at 05:53 UTC

    Sure, there are cases where two-argument open is mostly safe, but if you make a habit of using the three-argument form, you never have to consider whether the two-argument form is safe in any particular circumstance.