Note: Beware of the instructions in the link below. It has you do far more work than is necessary. See this follow-up article for details.
Here's the first big blog post I've seen about Strawberry Perl: How to install and set up Strawberry Perl
I am writing this article with much joy and glee.... Active State no longer has a monopoly on the issue of Perl on the Windows platform
I haven't read the Strawberry Perl docs, since I'm Windows-free. The blog post gives details about what tools are necessary to make the install, with links to the tools. Now, I thought that part of Strawberry Perl was that you wouldn't need any external tools, but maybe they're just for building CPAN modules.
Working on my Big Dirty PHP Project at work, I've found this bit of code in many places.
$categories = ""; $categories = Array();
Why is $categories set to an empty string, and then an array? It's not necessary to pre-initialize a variable before setting it to another value. So why is the code there? It's not just one case. It's throughout the codebase, where I delete the first line whenever I find it.
The original programmer is (thankfully) no longer around to ask, but I'm guessing it's superstition. Perhaps he had some problem that went away for an unrelated reason when he added the first line of the code. The problem is that he never considered why.
Here's another coding horror to avoid in Perl. Ever seen a regular expression by someone who wasn't entirely familiar with regexes and quoted everything whether it needed it or not?
if ( $name =~ /Marcus Holland-Moritz/ )
The hyphen in Marcus's name isn't a metacharacter, but the unsure, superstitious programmer will quote it anyway. "Eh, it doesn't hurt anything," he may reply, but it also demonstrates his non-mastery of regexes.
If you ever find a piece of your code where you can't understand exactly why it works, why every single statement exists, stop and rework it until you do.
Michael Schwern has written a column for Andy Oram's Beautiful Code blog called LWP::Simple - Simple Goal, Simple Interface. In it, he talks about minimizing the "gulf of execution" with a two-line easy-to-understand Perl program:
use LWP::Simple; my $page = get("http://www.google.com");
Bravo to Schwern to getting the words "Perl" and "beautiful code" together. I can't wait to see part two.
The news about Perl 5.10 is everywhere, and it didn't take that much emailing of news editors on my part. However, I have one regret.
I should have made it more clear in the announcement that Perl 5.10 is the first major change in the Perl language in five years. What I wrote was "Today the Perl Foundation announces the release of Perl 5.10, the first major upgrade to the wildly popular dynamic programming language in over five years." Unfortunately, that got shortened in headlines to the incorrect "first release of Perl in five years", which ignores 5.8.1 through 5.8.8, and has since been spread far and wide.
I'm glad the news is getting out there, but wish it were more accurate.
Dean Wilson reveals My Favourite Three Features in a recent blog post, but doesn't discuss my #1 feature of Perl 5.10: The say command.
Why love say so much? It's just the same as print with a "n" at the end, right? Yup, but that "n" causes heartache for me in life. See, I've been working on removing interpolation from my life wherever possible. For instance, we've probably all seen beginners do something like:
some_func( "$str" );
where the quotes around $str are unnecessary. (Yes, I know there could be overloaded stringification, but I'm ignoring that possibility here.) That function call should be done as:
some_func( $str );
By the same token, I don't use double quotes any more than necessary. Rather than creating a string as:
my $x = "Bloofga";
do it as
my $x = 'Bloofga';
It's not about speedups. It's about not making the code do anything more than it has to, so that the next programmer does not have to ask "why is this work getting done?" If the code doesn't need the double-quoting, then don't use the double-quoting.
I started down this road when I read this rule in Perl Best Practices, but ignored it. "Eh, no biggie," I thought. Then I started using Perl::Critic, and it complained about everywhere I was using double quotes. As I examined those complaints, I came around to realize that if you're having the computer do work, the next programmer has to wonder why.
So now we get the say command, and I get to eliminate at least 50% of my necessary string interpolation. Instead of:
print "Your results are:n";
I can now use:
say 'Your results are:';
So much cleaner. In a color-coding editor like vim, the distinction is even clearer, and as MJD likes to point out, "It's easier to see than to think."
Start using say. Even if you're not on 5.10 yet, you can use Perl6::Say for most of the places that say works in 5.10. Even better, stop using unnecessary interpolation altogether.