http://qs321.pair.com?node_id=11137602

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Howdy Monks,

I've used Perl in the past and was quite happy with it. But lots of folks use Python nowadays. So what is Perl better at than Python? Is my time better spent learning Perl or Python? And Perl faster than Python, especially when it comes to creating reports from text and putting in CSV or excel? Can Perl do parallel processing better than Python and most importantly, does regex and Perl Modules for CSV, ssh, excel, REST etc play well with parallel processing? I don't know anything about parallel processing but I'm sure I'll need it hence asking, because there's some text files that go 10000 lines or some that are 200MB PLUS in size..Asked a friend and he said Python is better at parallel processing so jus wanna know.

Replies are listed 'Best First'.
Re: What's Perl good at or better than Python. (FAQ)
by LanX (Saint) on Oct 15, 2021 at 20:31 UTC
Re: What's Perl good at or better than Python.
by stevieb (Canon) on Oct 17, 2021 at 05:21 UTC
    What's Perl good at or better than Python.

    Making me money. I make a whole lot more money doing Perl work than I did when I was coding in Python.

    A company can hire 50 people out of school, then another 50 who have been in the field a few years to write Python for a dime a dozen. Perl experts are much, much harder to come by, so the jobs typically pay far more. I work for a company doing full time Perl work, and I still have several very well paying clients who use my services several times per year. The hourly rate for those clients is significantly more than I could (and have) made by doing similar work in Python.

    With that said, the jobs are much harder to come by. You're all but guaranteed a job if you're worth your salt with Python coding.

    Perl is and always been hands down my favourite language, and I never see that changing. I even prototype most of my code in Perl for most of the other languages I write in (C/C++, C#, Python etc), even my microcontroller code before I write it.

      > Perl experts are much, much harder to come by, so the jobs typically pay far more

      Which will drive the companies further away from Perl ... :(

      Don't you think?

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re: What's Perl good at or better than Python.
by Marshall (Canon) on Oct 17, 2021 at 00:07 UTC
    I am just starting to learn Python.

    Python will be much less efficient than Perl in multi-threaded applications due to the GIL (Global Interperter Lock). To get around that, Python provides the multiprocessing module to run multiple instances of the Python interpreter on separate cores. State can be shared by way of shared memory or server processes, and data can be passed between process instances via queues or pipes. You still have to manage state manually between the processes. Plus, there’s no small amount of overhead involved in starting multiple instances of Python and passing objects among them.

    Perl multi-threading can be quite efficient. This is best seen in a "number crunching" task. I had one job with 20K items to process. Processing each object required a lot of CPU. When I split the job onto 4 cores, the overall task completed 3.7-3.8x faster. You can't get 4x because there is some OS and intra-thread overhead. I haven't coded that application in Python, but if I did, I don't expect those excellent results.

    Python requires obscure statements to increase speed.
    There is a concept called "List Comprehension".
    Basically if you squeeze the loops into a single statement, it will run faster. That is not true with Perl. Perl allows easier to understand code that runs just as fast as shorter, more obtuse code.

    Python: def print2D(table) : # print LoL print('\n'.join([' '.join([str(score) for score in row]) for row i +n table])) Perl: sub print2D { my $table_ref = shift; foreach my $row_ref (@$table_ref) { print "@$row_ref\n"; } }
    Python is now the most popular programming language - there is little doubt about that because it is being taught in essentially all CS curricula world wide.

    If you are processing some very large file, with a very small amount of processing per line, multi-threading won't help at all if you are reading the file in serial, linear fashion. The processing time will be dominated by the time to read the file from disk! Even doing something complicated and "tricky" to say give 1/4 of the file to each of 4 threads won't help because at the end of the day, how fast you can read the bits off of the disk will be limiting (assuming again the processing per line is relatively "cheap").

    Update: And Perl faster than Python, especially when it comes to creating reports from text and putting in CSV or excel? Perl has C libraries for CSV stuff - they run very quickly. I suppose that Python has those also. I am not sure that it makes much difference. We would have to write some benchmark code.

    Update2: Some years ago, I talked with a guy who wrote code for the high volume day commodity trading market in Chicago. They used Perl to parse the incoming trades and then C to crunch the data for the actual trading algorithms. I would have thought that C would have been used for all of it. But evidently not true (at least at the time). Perl is quite good at the right job.

Re: What's Perl good at or better than Python.
by perlfan (Vicar) on Oct 16, 2021 at 17:59 UTC
    I don't look at it in a technical light, but rather how do you wish to be shaped by the tools you use and create; and the people you interact with and learn from. For example, here's a short list of how I view the choice differential.

    Use Perl if:
    • primary use unix, BSD, linux
    • care about portability and longevity of your work
    • prefer master of the language and workflow efficiency
    • are familiar with and like the Unixtm philosphy for tools
    • believe that a user community exists such that you tend to mastery (i.e., believe that iron sharpens iron)
    • see the value of an unbroken linkage to unix wizards of the past
    • not only comfortable with, but are actually attracted to the idea of being among a class of remnant working and toiling for the day that Perl will be rediscovered and appreciated
    Use Python if:
    • primarily use Windows or are agnostic to the OS
    • don't care about the longevity or portability of your work
    • wish to be a jack o' all trade
    • prefer to be part of the herd

      Both Python and Windows work equally well regardless of the OS. In fact, I code in both languages on both Unix and Windows, and even use the same IDE cross-platform and in many cases, cross-language.

      About the jack of all trades comment... I'm a jack of all trades in both languages, but I've also written some extremely complex and significantly focused applications and suites using both Perl and Python. In reality, it was Perl that allowed me to become such a good jack of all trades. That skill just transferred over to other languages nicely.

      I think you vastly underestimate Python.

      The sheer number of new people who are learning Python vastly exceeds the number of new people who are learning Perl. The huge amount of code that is currently being written in Python will ensure its longevity. From what I can see, continuing Python 3.X releases show a vibrant language that is expanding with new features and capability.

      I will confess to also being somewhat of a "Perl bigot" and I love Perl. However, Python is a "growing force" whether we "like" it or not!

      There will be certain tasks that Perl is much better at than Python. There will also be a lot of tasks where the difference just doesn't matter.

Re: What's Perl good at or better than Python.
by Anonymous Monk on Oct 16, 2021 at 14:00 UTC

    I have heard it said that Python is faster than Perl, but the only actual comparison I have done (parallel implementations of Conway's "Life") says that Perl is slightly faster but Python has a slightly smaller memory footprint. My opinion is that if speed is truly a consideration you will reject both languages in favor of a compiled language. My C implementation of Life had a much larger memory footprint (no readily-available hash implementation) but was orders of magnitude faster than either Perl or Python.

Re: What's Perl good at or better than Python.
by Anonymous Monk on Oct 19, 2021 at 22:45 UTC
     Whoa!! Thanks a lot folks!!Thanks for sharing your knowledge!!!
Re: What's Perl good at or better than Python.
by Anonymous Monk on Oct 15, 2021 at 21:02 UTC

    Ok, first reply and no hate, this was unexpected 😀. Just some good logical answer and update. You folks are not fanboys. But may be I said that too soon 😂