Tim Hammerquist <> wrote in
news::
> John Bokma <> wrote:
>> Tim Hammerquist <> wrote:
>>> John Bokma <> wrote:
>>>> "A. Sinan Unur" <> wrote:
>>>> > * Use the three argument form of open.
>>>> >
>>>> > unless ( open my $old, '<', $file ) {
>>>> > push @errors, "Failed to open '$file': $!";
>>>> > next FILES;
>>>> > }
>>>>
>>>> Why?
>>>
>>> Be cause there's no longer MTOWTDI.
>>
>> There always is 
>
> No. This is Pyth^W the New Perl. 
>
> (The following is *not* directed at Mr. Bokma.)
....
> To bring this slightly back on topic, I can't find any place
> where perlfunc says the 1- or 2-arg form of open() is
> deprecated. In fact, it mentions several conveniences offered
> by the 1-/2-arg form.
I did not go into detail, because I thought it wasn't as important an
issue as attempting to read from and write to possibly unopened
filehandles.
While '>temp.txt' is quite safe, with "<$file", $file is interpolated.
That interpolation can have unintended effects.
In the OP's case, there is no guarantee on what characters may appear in
the filename. In that particular case, perldoc -f open specifically
recommends the 3-argument form:
<blockquote>
Use 3-argument form to open a file with arbitrary weird
characters in it,
open(FOO, '<', $file);
otherwise it's necessary to protect any leading and trailing
whitespace:
$file =~ s#^(\s)#./$1#;
open(FOO, "< $file\0");
(this may not work on some bizarre filesystems). One should
conscientiously choose between the *magic* and 3-arguments form
of open():
</blockquote>
It can also be easier to read because it separates the mode from the
file name.
If the OP had limited the possible filenames to be processed by
filtering them in some way, I would not have made the recommendation.
Therefore, I find it better to stick with the three argument form unless
there is a specific reason to prefer the two argument form.
Sinan
--
A. Sinan Unur <>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc...uidelines.html