Sign in to follow this  
  • entries
    35
  • comments
    67
  • views
    20719

I Love Perl...and I Hate Perl

Sign in to follow this  
Devnull

501 views

I've worked with Perl for over 10 years now, off and on. At various times, I've made a living at it. In fact, if I had to rank my skills in various languages, it would probably go somethine like this:

Guru: C++, Perl
Expert: Java, SQL, HTML, javascript
Good: DOS, C-Shell, Bourne-Shell
Novice: Lua, Python, Visual Basic, PHP

I can do some pretty amazing things with Perl - it's a wonderful language that is almost without peer in parsing and batch processing. (Lots of people say that Python is better, and from what I can tell, it can do pretty much all that Perl can, but I just have a hard time liking it. it's an aesthetics thing for me - I can't stand the enforced indentation).

Like any other language, though, Perl has it's good and bad points. On the plus side, Perl allows some very rapid development of certain types of applications - text processing, batching, etc. It has a lot of built-in data structures and it's way of handling data is very powerful.

On the down side, there are almost always a number of different ways of writing the same code and if you're not careful, you can write some almost completely unreadable code. Perl is well known for obfuscated code and seems ideal for doing "clever" tricks that are optimized, but take years of practice before being able to understand them or use them wisely. Basically, what I've found is that every Perl programmer seems to have their own unique style, not just in formatting, but in what parts of the language they use to accomplish the same tasks.

As a small example, take the methods for passing parameters to a method. To pass an integer, a string, and 2 arrays to a method, there's a number of different ways that I know of off the top of my head:


&foo( $n, $s, \@a1, \@a2 );
sub foo
{
my ( $n, $s, $aref1, $aref2 ) = @_;
my @a1 = $$aref1;
my @a2 = $$aref2;
}



&foo( $n, $s, \@a1, \@a2 );
sub foo
{
my( $n, $s ) = ( @_[0], @_[1] );
my @a1 = @{ @_[2] };
my @a2 = @{ @_[3] };
}



foo $n, $s, \@a1, \@a2;
sub foo( $$@@ )
{
my $n = shift;
my $s = shift;
my @a1 = @{ @_[0] };
my @a2 = @{ @_[1] };
}



foo $n, $s, @a1, @a2;
sub foo2( $$\@\@ )
{
my $n = shift;
my $s = shift;
my @a1 = @{ @_[0] };
my @a2 = @{ @_[1] };
}



foo( $n, $m, \@a1, \@a2 );
sub foo ($$**)
{
local( $n, $s, *a1, *a2 ) = @_;
}


And there's even more ways to do this as well, but I'm not including them all for brevity - I just wanted to illustrate my point.

Ultimately, this flexibility in syntax is both a good and a bad thing - it makes the language very powerful and flexible, but it also makes it virtually unreadable at times and means that everyone is going to get used to doing things in different ways - making other people's Perl code much harder to "translate".

Anyway, there really isn't a lot of point to this entry except to say that I love Perl...and I hate it. This came up, of course, because I've been doing a few "simple" scripts in Perl lately for work. As always happens, the "simple" job turns into a massive behemoth of a job and the scripts to handle it get convoluted, loaded with special-case handlers, etc. Perl allowed me to do some very elegant solutions, but everyone else who's looked at the code has just boggled because it's...well, Perl, and they didn't know Perl could do many of the things I did with it.

The gist: code reviews of Perl are a bitch =)
Sign in to follow this  


1 Comment


Recommended Comments

I love the way you can parse the URL header and then put all the queries after the question mark into an array in one line of code. But after doing an entire web project in perl on a server that had no debugger (if the page loaded it worked, if the page was blank you had made an mistake) I can see the annoying side of perl.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now