cancel
Showing results for 
Search instead for 
Did you mean: 
Klaatu
Mission Specialist
Mission Specialist
  • 4,334 Views

Perl5 or Perl6 ?

Jump to solution

I've been writing a bunch of (g)awk scripts lately, and it occured to me that instead of messing around with sed and awk, I'd probably be better off just learning Perl, which I feel probably offers a lot more features than sed and awk combined. I figure Perl is useful for the usual one-liner commands, scripts, and even GUI toolkits and hundreds of libraries, and no real vertical limit.

My problem is this: should I learn Perl 5 or 6?

Apparently 6 is *not* a replacement for 5, but its existence makes me wonder how 5 can possibly progress with its next obvious version number occupied.

I'm open to the advice that Perl in general is too much a mess to bother with, but in that case, I'd be interested in knowing the best replacement for it, with the requirements being upward scalability, excellent regex, and amazing text parsing.

0 Kudos
1 Solution

Accepted Solutions
Klaatu
Mission Specialist
Mission Specialist
  • 2,774 Views

It's been settled.

Perl6 has now officially become Raku.

Perl5 (version 5.32 specifically) is becoming Perl version 7.

I've started using Perl 5.32 in scripts, and I'm loving it.

View solution in original post

0 Kudos
5 Replies
Scott
Starfighter Starfighter
Starfighter
  • 4,331 Views

Instead of Perl, I would suggest instead trying to solve your problem with Python.  Perl's usage is on the decline, and if you're going to be learning a new skill/language anyway, why not spend time learning one that has much more utilization within the Red Hat ecosystem?

-STM

RRR
Flight Engineer Flight Engineer
Flight Engineer
  • 4,324 Views

I saw this post on the landing page and just had to check how soon we'd see the inevitable recommendation to dispense with perl and go with python.

If you are starting from scratch with no perl or python background, I'd  agree with Scott with a couple of caveats.  First, if you have been working with sed and awk you might find perl more "shelly".  In the longer run, you are likely to find python the better investment of time and effort but if you've got a project where getting it done quickly is the highest priority (not advocating such prioritization, just acknowledging that sometimes it's reality), it might be worth going with perl 5.

Second caveat:  you mention amazing text parsing.  Advantage: perl on that one, methinks.  Regex is probably a wash between the two.  "Upward scalability" could mean a number of things, but for any of them I'd say Advantage:  python.

Therefore, the two big things that only you can answer are (1) how important is getting up to speed quickly, and (2) how heavily you want to weight text handling..

 

Klaatu
Mission Specialist
Mission Specialist
  • 4,315 Views

Thanks for the insight, all.

I use Python for lots of stuff, but text parsing tends not to be one of them.

Maybe I just haven't found the right library/module, but I'm not convinced on Python's ability to wrangle text the way awk can (and part of the reason for this question is the assumption that Perl is an improvement on awk for text parsing plus all the extra libs and functions that Perl has available).

0 Kudos
oldbenko
Moderator
Moderator
  • 4,307 Views

It *is* called Practical Extraction and Reporting Language, afterall, so you're kind of right in assuming it would be better for that purpose.

Perl is notorious for poorly written code and almost synonymous with it in the eyes of most people that disregard it publically, but I have to tell you from personal experience: if you want readable code, that's what you will write.

I was never a fan of "perl -e" (which is the one-liner option) because there are very few use-cases for one-liners where a slightly longer pipeline wouldn't do the trick (a most notable exception being a custom sorting algorithm where you have to recognize and understand a data structure and extract the key to sort on, for example - yes, you can do this with a one-liner).

I had written a ton of object-oriented Perl code in my times (say, an email-to-sms gateway for an online services provider, complete with logging, rate-limiting, reply-by-sms and other nice features), and I must say I loved every moment of it. Even getting back to maintain the code wasn't too bad because as I said, if you want readable code, you'll write it. It was my memory that was the problem, not the code (which probably tells you how often I had to do it).

Where I'd say Perl's reach ends is concurrency: process and/or thread management, and even there the event framework did a lot of good for some use-cases.

As for Perl5 vs. Perl6, have a look at the Perl5 to Perl6 differences document. You'll see that essentially, the logic of how you develop in Perl doesn't change - the peculiarities do. I'd say the biggest difference is that OO isn't a hack any more (which can be good or bad, depending on what degree you were inclined to bend the rules to in Perl5, but again, that will just determine how painful the change of outfit is going to be for you, not what you can do in either of the versions).

Ultimately, as in any language, it really boils down to the ecosystem. What libraries are there that make life easier for you (not having to reinvent the wheel for the millionth time)? How well are they maintained (and proctored)? What tools do you have that help you produce better code?

I argue that Perl5 has a significant advantage there because of, apart from the obvious advantage of time it's been around for, the PerlXS framework that made it really easy to write extensions, and the fact there is an actual perl-to-native compiler (if horrific) that allows you to produce binary executables when you need to.

A black cat crossing the street signifies that the animal is going somewhere.
[don't forget to kudo a helpful post or mark it as a solution!]
0 Kudos
Klaatu
Mission Specialist
Mission Specialist
  • 2,775 Views

It's been settled.

Perl6 has now officially become Raku.

Perl5 (version 5.32 specifically) is becoming Perl version 7.

I've started using Perl 5.32 in scripts, and I'm loving it.

0 Kudos
Join the discussion
You must log in to join this conversation.