Why is three-argument open calls with autovivified filehandles a Perl best practice?

Viewed 6397

I've got two questions about the Perl open function:

1) I seem to remember from Perl Best Practices that the 3-argument version of open is better than the two argument version, e.g.

open(OUT, '>>', $file);

vs.

open(OUT, ">>$file");

Why is that? I was trying to tell somebody to use the 3-argument version the other day but couldn't seem to back it up with anything.

2) I also seem to remember autovivified filehandles being favored over bareword filehandles (they called something different)? And also couldn't remember why, e.g.

open(my $out, '>>', $file);

vs.

open(OUT, '>>', $file);

Is it a strict thing? I seem to remember being able to use OUT with strict but I can't remember.

3 Answers
Related