Ugly Old Perl
blog.laufeyjarson.com
blog.laufeyjarson.com
Then again, removing language constructs is a sure-fire way not to get any adoption of the new version (cf. Python 3).
In my case, it's not old Perl idioms that stick around, it's old PHP idioms. Like Perl, PHP too has moved forward, especially with 5.3. But because the old code continues to work ad-infinitum (how many years did it take for PHP 4 to die? Right. It's still alive, even though most PHP4 code runs unaltered in PHP5), nobody is taking advantage of the new features.
While I can understand this in public projects (you want to be as broadly compatible as possible), for private projects, I certainly would want to use the latest and greatest as it helps both keeping the code clean and future-proof it.
Here in the office, we've introduced the concept of a raptor incident (http://xkcd.com/292/). We use this to denote old idioms being used and general lazyness-related code smells.
We are counting the raptor free days and whoever causes a raptor incident will get the the accumulated stack of post-its with incrementing numbers counting the raptor-free days.
It already helped tremendously at keeping people concerned about their output.
Perl is still very much alive and not at all stuck in a bad place. It may be easy to get that impression in your local circumstance but in the larger sense Perl is thriving. It's even gasp still grabbing young developers. I wouldn't worry too much about it.
Constructively, though, what is wrong with the code snippet? The improvements he lists don't improve this case at all. Three-argument open vs two here is debatable (I doubt $runpath is insecure input), but fancy filehandle-in-a-variable doesn't gain anything when it's just in use over three lines.
I'm not sure why using a lexical variable to store a filehandle you only need lexically is more fancy than storing it in a globally accessable package typeglob for anyone to use and modify. But it does give you the advantage that your garbage collector will close your file handles instead of you having to do it manually. If I see close($fh) in my own code, I know I had a reason other than "I didn't need it anymore."
open my $fh, ">$file" or die "...";
will append to target if $file contains ">target". Code like this: open my $fh, '>', $file or die "...";
explicitly tells Perl what the mode and what the filename is, so there can't be any confusion.Using lexicals instead of typeglobs means you store the filehandle in a lexical variable instead of making it globally accessible in your package.
my $file_path = Path::Class::dir("some_path")->file("file_name");
my $fh = $file_path->openw();
$fh->print("my line\n");
$fh->close();
Or for reading the whole file quickly, instead of the @var = <FILE> idiom -- my @var = $file_path->slurp();Another reason might be that you're writing a CPAN module and don't do much with files. If you just use it to write a debug log when an environment variable is set, you might not want to include another dependency.
What your code demonstrates very good in my opinion is the fact that lexical filehandles are just more interoperable. You can pass them around transparently like any other reference, use modules that pass them around, and so on.
And there's a lot of good stuff here, http://www.modernperlbooks.com/mt/index.html.
* Planet Perl Iron Man (http://ironman.enlightenedperl.org/)
* Perlsphere (http://perlsphere.net/)
http://modernperlbooks.com/mt/index.html
http://www.effectiveperlprogramming.com/
From the command line:
> perldoc -f open
Update. See the major version deltas for a complete summary of new features: