Is this why Perl sucks?

I am trying to shift gears to re-focus on a project where I have been pretty sluggish and seem to have hit a some kind of block. Checking Perl blogs, I noticed there seems to be a lot of people worried about name changes and stuff. Apparently, there are some people who think Perl sucks. Based on what they know about Perl 4, they have dismissed Perl 5, and are holding out for Perl 6. If only Perl 6 were not named Perl, those people would realize how wonderful Perl 5 is. Or something like that.

I am sure there is some truth to that. However, I am reasonably certain that people who loudly proclaim “Perl sucks!” aren’t interested in Perl 6 either. Personally, Perl made sense to me for the first time with 5.8. I had used Z80 assembly, Pascal, Fortran, APL (not that I remember any of it), C, forays into C++, and Java (in that order) along with SAS, S-Plus etc prior to that. It has been pointed out to me that Perl became my favorite language at a time after Perl’s prominence had peaked. I was even asked “Python was available when you switched to Perl. How can you justify that?”

I don’t know. Perl just made sense to me, especially since I already had at my disposal CPAN which removed so much drudgery out of writing programs to do what I wanted.

That does not mean I decided to remain ignorant of Python and later Ruby. I am conversant in both, but have never felt at home the way I do when immersed in Perl.

It does not take a genius to realize that Perl 6 is different than Perl 5. Maybe I am a simpleton, but I just don’t see why Perl 6 should have any bearing on what I do using Perl. Clearly, Perl 6 is related to Perl 5. This is probably a bad analogy, but did anyone feel compelled to change C to something else because of C++. Did the existence of C++ stop anyone from writing C where it was appropriate?

On a lighter note, I decided to search Google for “Perl sucks.” The second hit is a 2008 blog post by someone called Python Guy.

He (I am going to assume Python Guy is a “he”) compares the following Perl code:

my @subgroup = (scalar(@{$group}) > $maxNumInSubgroup) ?
    @{$group}[0..($maxNumInSubgroup-1)] :
    @{$group};

to make the case that Perl sucks compared to Python.

First, in case it is not obvious to you, I’ll point out you should not use @{$group}[0 .. ($maxNumInSubgroup-1)] to get the subset because if $maxNumInSubgroup is larger than the size of the array referenced by $group, using the array slice would result in allocation of extra undef elements at the end of @subgroup.

Now, the Python solution is appropriately elegant:

subgroup = group[:maxNumInSubgroup]

Is this really why Perl sucks?

Anyone can see the original Perl code is ugly (not the least because of the Camel case variable names ;-)

However, if you do this kind of thing often in your code, it is straightforward to put it in a function:

use warnings; use strict;
use Data::Dumper;

my $group = [ qw(a b c d e) ];

my $subset1 = make_subset($group, 3);
my $subset2 = make_subset($subset1, 1);

print Dumper($subset1, $subset2);

sub make_subset {
    my ($ary, $max_elements) = @_;

    return [ @$ary ] if $max_elements > @$ary;
    return [ @$ary[0 .. --$max_elements] ];
}

Now, is that really so bad that someone would be motivated to shout from the rooftops, “Perl sucks!”