in reply to open my $fh, MODE, FILE vs. open my $fh, "MODE FILE"

As far as I know, the main problem with 2-arg open is if the beginning of the file could be misunderstood as the mode. That shouldn't happen if you explicitly specify the mode and have a space before the filename.

But I prefer the 3-arg form anyway.

  • Comment on Re: open my $fh, MODE, FILE vs. open my $fh, "MODE FILE"

Replies are listed 'Best First'.
Re: Re: open my $fh, MODE, FILE vs. open my $fh, "MODE FILE"
by bart (Canon) on Feb 03, 2004 at 01:31 UTC
    There's more to it. Whitespace on both sides of the filename gets stripped. Tough luck if your filename actually has whitespace on either end of its name...

    From perldoc -f open:

    The filename passed to open will have leading and trailing whitespace deleted, and the normal redirection characters honored.
      Tough luck if your filename actually has whitespace on either end of its name

      If you have filenames like that, you'll have trouble with more than just Perl. Even whitespace in the middle of filenames has a tendency to break things.

      I would personally be more concerned about the backward compatibility. There are a lot of people out there still using 5.003 for one reason or another.

      Of course, if you're using newer Perl features anyway, like unicode or threads, then that consideration becomes moot and you may as well use the three-arg form.


      $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/