Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

What technical benfits perl offers over python + few more questions.

by Anonymous Monk
on Nov 13, 2021 at 10:48 UTC ( #11138774=perlquestion: print w/replies, xml ) Need Help??

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

Hello Monks,

I've visited the PerlMonks monastery occasionally to glean over the fabulous and impartial help offered here.

I come here now with a question, that I hope will not rile you all.

I intend to use a scripting language for gathering reports, most of which will be filtering through command line outputs (The cli application is accessed through Ubuntu Linux). It has been over 10 years that I have written a script in Perl. Back then too, It was nothing earth shattering, just gathering command outputs and filtering stuff through regex. This time though, I need to gather outputs and redirect to an existing excel file, either populate the blank fields or update the existing fields with new data.

Most of my organization's current scripts are written in Python, but I will be the only person using the scripts I write and when it comes to capturing command line outputs, I like Perl's approach rather than the subprocess popen, communicate etc offered by python. Also, I have a preference for Perl's regular expressions than Python's. I am not dissing Python, it is a great language. But I like Perl a lot and want to use it for my work. I checked a few articles though, and they all seem to say that 1) Python offers better error handling than Perl 2)Functions are first class citizens in Python, 3)Even for the kind of reporting I am looking for, Python would be a better choice.

Most Monks here have played with and professionally used more than 1 language, and I think Python would be a part of that gamut.

Second and equally important part is, I need to put Perl in my resume as the only language I use for automation, thinking it will give me an edge over those who mention Python as the only scripting language they use. So is there any advantage in learning / refreshing Perl? How is the job market for Perl? Is it really low in demand like how a lot of articles/videos say on the internet?

Ideally, I would like to refresh my Perl knowledge and learn Python too, however, given my current workload, I can pick only one as of now, and may be 4 to 5 months later, I can focus on 1 more language. That and the fact that it will not be a good idea to learn two languages simultaneously, is what is keeping me from re learning 1 language while learning a new one from scratch. Besides, I already know Perl to some extent, and refreshing it will (I think) take less time than learning another from scratch. My learning method is also quite unusual in that I focus on what I want, read up stuff on that (that's why I wrote the popen communicate point above) rather than learning everything and then write scripts.

Any help or guidance will be much appreciated

  • Comment on What technical benfits perl offers over python + few more questions.

Replies are listed 'Best First'.
Re: What technical benfits perl offers over python + few more questions.
by LanX (Sage) on Nov 13, 2021 at 10:58 UTC

      Thanks LanX! Beat me to it by a few nano-seconds. :)

      On reopening that list of nodes just now, I was amazed at how many times this sort of question has been asked here. At the risk of stating the obvious, our enquiring anonymonk should perhaps focus on the nodes in its "Recent Nodes (2020-2021)" section ... followed of course by reading every other node in that list. ;-)

        Thanks eyepopslikeamosquito for compiling the list and putting it accessible in O(1) on your home-node ... :)

        > Beat me to it by a few nano-seconds. :)

        For next time I'll delay my AI reply bot to some nano-seconds more ...

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

Re: What technical benfits perl offers over python + few more questions.
by hippo (Bishop) on Nov 13, 2021 at 11:46 UTC
    I checked a few articles though, and they all seem to say that 1) Python offers better error handling than Perl

    It is a shame that you have not linked to these articles - not even one of them - so that we can discover in what way the authors think that Python offers better error handling. All I can do therefore is say that in all my many years of working with Perl never once have I thought "Perl's error handling could be better".

    2)Functions are first class citizens in Python

    Super. What does that give you that you can do with functions in Python that you cannot do with functions (subroutines) in Perl?

    3)Even for the kind of reporting I am looking for, Python would be a better choice.

    Again, no link so no reason why. Here, I'll say it: "Perl would be a better choice". I present as much evidence to back up this claim as you have done so far, ie. none.

    Actually, I'll do better than that. Perl has CPAN and CPAN has many modules for working with accursed Excel spreadsheets should you so need - even on non-native Excel platforms. Perl is (almost entirely) backwards compatible with itself so you don't need to ask, "python2 or python3"? Perl is already installed on any O/S you might be using (except MSWin, of course).

    For any given task, to choose the language which is most appropriate you must consider the key aspects of that task and then you can whittle down your choice to those languages which satisfy those requirements. Then you can dig into nuance. And finally there is the choice of which language you want to use and why. I almost always want to use Perl because (a) it has all the tools, (b) it is expressive and (c) is it (to me) intuitive. Its speed and ubiquity are just bonuses.


    🦛

      Hi Hippo

      Here is one of the links that talks about exceptions not being part of Perl. My bad again, I got mixed up with errors and exceptions, and if you berate me for that I would totally understand- https://www.oreilly.com/library/view/mastering-perl/9780596527242/ch12.html

      Given below is paragraph from the chapter -

      Exceptions Perl doesnít have exceptions. Letís just get that clear right now. Lik +e some other things Perl doesnít really have, people have figured out + how to fake them. If youíre used to languages, such as Java or Pytho +n, set the bar much lower so you arenít too disappointed. In those ot +her languages, exceptions are part of the fundamental design, and tha +tís how Iím supposed to deal with all errors. Exceptions arenít part +of Perlís design, and itís not how Perl programmers tend to deal with + errors.

      Unfortunately I could not find other links. I was just going from one article to another and that is how I stumbled across the said articles.

      Note:- I am not hear to badmouth about Perl. Just really badly wanting to get some clarity (which the ensuing answers have provided in truckloads).

        Exceptions are not an explicit part of the Perl language, but fatal errors are and can serve a similar purpose. However, as with many other topics, exceptions are well catered for on CPAN with almost 4000 results for "exception". If you do want to use exceptions with Perl there are many ways to do so.


        🦛

        Perl has exceptions, and that's nothing new. Exceptions are thrown using die, and caught using eval BLOCK.

        Differences:

        • Perl operators don't throw exceptions, while the corresponding IO libraries in other languages might.

        • Perl exceptions don't automatically come with a stack trace, whereas it's common elsewhere. It's definitely possible to get stack trace from exceptions in Perl, through. See Carp::Always.

Re: What technical benfits perl offers over python + few more questions.
by talexb (Chancellor) on Nov 13, 2021 at 15:31 UTC
      I intend to use a scripting language for gathering reports, most of which will be filtering through command line outputs (The cli application is accessed through Ubuntu Linux). It has been over 10 years that I have written a script in Perl. Back then too, It was nothing earth shattering, just gathering command outputs and filtering stuff through regex. This time though, I need to gather outputs and redirect to an existing excel file, either populate the blank fields or update the existing fields with new data.

    Cool. I use Getopt::Long for dealing with command line arguments, and in the past I have used Spreadsheet::ParseExcel for reading Excel spreadsheets. Both modules work very well.

      I checked a few articles though, and they all seem to say that 1) Python offers better error handling than Perl 2)Functions are first class citizens in Python, 3)Even for the kind of reporting I am looking for, Python would be a better choice.

    OK, those are valid comments .. but it would be nice to see a link to the articles in which these claims are made, so that we can answer the specific issues that are raised. 1. Perl does a pretty good job or error handling (Try::Tiny comes to mind); 2. I'm not sure I understand how a function can be thought of as a second-class citizen; and 3. One of the things that Perl does an excellent job at is reporting. (I think reporting was one of the tasks it was used for, very early on). So at this point, I'd quote wikipedia.org and say, "Citation(s) required".

      Ideally, I would like to refresh my Perl knowledge and learn Python too, however, given my current workload, I can pick only one as of now, and may be 4 to 5 months later, I can focus on 1 more language.

    If you want the most bang for the buck, I would suggest continuing with the language you already know (Perl) so that you can be as effective as possible at your job. If you have time after work, you could spend an hour here and there learning Python, starting off with simple programs, and perhaps moving on to more complicated tasks, such as parsing command line arguments.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      > 2. I'm not sure I understand how a function can be thought of as a second-class citizen;

      because that's FUD

      "First class object" aka citizen basically means you can pass functions around as arguments to other functions. E.G. most BASIC dialects I've seen couldn't do that.

      It's a necessity for functional programming...

      Perl is actually better in functional programming, since Python is restricting lambdas to one expressions only, while anonymous subs are free.

      And Python doesn't offer any block prototype to make it even easier like sub foo (&) { $code = shift; ... }

      Superficial people will claim that the need to explicitly reference named subs in Perl with ...

      \&foo

      means they are not first class.

      Superficially so because almost everything in Python is implicitly a reference.

      Now, who said explicit is better than implicit again ...???

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

          because that's FUD

        Huh .. too bad. I dealt with FUD with Microsoft continually slamming OS/2 in the late 80's, where we slagged Windows NT on the Canopus form on Compuserve. Good times.

        I developed code in C before moving to Perl in the late 90's, and was advanced enough that I was comfortable using function pointers in my code .. so when I wanted to do the same thing Perl, it was there already. Perfect, because being able to declare a callback function (one example of a function pointer) is extremely handy.

        And I don't really care what the TIOBE results say .. if a CTO contacts me to say 'Perl developers are really hard to find' and 'Are you available?', I don't find the burning need to go learn a different language. And, of course, the Perl community has been very supportive and welcoming. So I'm not going anywhere anyway. :)

        Alex / talexb / Toronto

        Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      OP - in addition to the advice above, I'd like to point you to the concept of a modulino. If you're doing mostly scripts, this approach will allow you to walk the line between scripts and modules (libraries). Which is good for "code reuse" when it makes sense. I also highly recommend you take a look at Util::H2O. It is great for cleaning up old crust scripts that heavily use hash references (the sign of a mature Perl developer) and can make your modulinos even more pleasant to work with.

      Finally, I must also point out. A lot of times it's okay to use bash. I maintain a mix of Perl and bash scripts; your tolerance and own needs will guide you where the "line" for that decision is.

        Which is good for "code reuse"

        Doing

        package Modulino; sub main { } caller() ? 1 : main;
        perl "$( perldoc -lm Modulino )"
        is not better for code reuse over the traditional
        package Modulino; sub main { } 1
        perl -MModulino -emain
Re: What technical benfits perl offers over python + few more questions.
by tangent (Vicar) on Nov 13, 2021 at 17:02 UTC
    If you want to do a job properly the language you use only makes up a portion of the overall picture. Other skills are also important, things like a robust testing regime, version control, consistent style using best practices, security, etc. When you learn to do these things correctly in one language they are easily transferrable to another, the effort put in will not be wasted.

    While I do all my backend work in Perl I also do a fair bit of frontend work, which means I have to use Javascript. I have never really had to 'learn' Javascript as I have mostly been able to write it in a similar style to the way I write Perl, and will look up the odd thing on a case by case basis.

    I also do some Wordpress work which means using PHP, and the switch to that is even easier. Everyone looks down on PHP but Wordpress powers 65% of CMSs today and there is tons of work.

    As for Python, the few times I have had to deal with it didn't go too well - the change in mindset was painful and slowed me down significantly. I'm sure others will disagree, but I don't think the transition between Python and the other languages mentioned is as seamless as that between Perl. So for me, Python is the outlier and if I were to focus on another language I would probably choose Javascript.

Re: What technical benfits perl offers over python + few more questions.
by bliako (Monsignor) on Nov 13, 2021 at 19:20 UTC
    I need to gather outputs and redirect to an existing excel file, either populate the blank fields or update the existing fields with new data.

    I would start from there. Make sure that existing CPAN modules on Linux can do what you need exactly.

Re: What technical benfits perl offers over python + few more questions.
by perlfan (Vicar) on Nov 13, 2021 at 16:26 UTC
    Higher Order Perl (1) has become the classic work on functional Perl (and it's free).

    > I am not dissing Python, it is a great language

    Python programmers are generally a self-loathing lot. I have never met anyone who loves Python like what you see in Perl, Ruby, or even PHP. Their "virtualenv" is also a cruel joke. Python 2 or 3? Please. Perl has least been robust enough to thrwart off such attempts at balkinization: Perl 6, Perl 7, One-Way-To-Perl-OOP, etc.

    My general response when it comes to "Perl or Python" is pretty well summed in my reply to a recent thread, Re: What's Perl good at or better than Python.. There are other good replies to that OP.

    > Most Monks here have played with and professionally used more than 1 language, and I think Python would be a part of that gamut.

    I avoid Python at all costs. Why? Mainly because, unlike with Perl, the scripts rarely find longevity or age well. Perl has its crust, but most journeymen who carry a toolbox of Perl scripts find it safe to assume they can use their scripts (or modules) pretty much anywhere.

    > How is the job market for Perl? Is it really low in demand like how a lot of articles/videos say on the internet?

    No, lies! However, I must warn you against entertaining job postings that require 50 years experience with PERL. Impossible I say! You make your own demand. Perl is an essential skill that will either lead you to or be part of a journey to Unix Wizardry. It's up there with sed, awk, and ed - no wonder Perl is simultaneously all of them and none of them (2).

    Learn Perl. Join the remnant. We are strong even if silent and mostly content to keep things running while the kids play with their fads like python and javascript - and the handful of useful applications that depend on them (mailmain, 80% of new websites, etc).

    Finally, I'd like to point out that Python was only ever a thing due to MASSIVE corporate and gub't funding. Google and Apple are even trying to kill this cancer; OTOH Apple literally can't remove perl from Mac OS base and FreeBSD just doubled down on some reliance on Perl with their very recent move to git after being in subversion forever.

    (updated, added references)

    References

    1. https://hop.perl.plover.com
    2. e.g., https://github.com/briandfoy/PerlPowerTools
Re: What technical benfits perl offers over python + few more questions.
by Anonymous Monk on Nov 13, 2021 at 17:56 UTC

    Respected monks

    Thank you for your advice. Yes I should have checked existing threads, but I did not. Sorry. However, your answers were quite eye opening. Thank you. The advice of focusing on refreshing Perl and learning a tiny bit of Python everyday seems like a good suggestion. I'm currently installing Linux on my personal laptop hence will not be able to post links immediately but I'll try to search and post them. once I find them. Posting this answer from my phone.Thank you again Monks.

      To my detriment, I rarely search the rich archives myself, the links to other threads is just our attempt to give additional dimension to the answers you're likely to receive in your post.
Re: What technical benfits perl offers over python + few more questions.
by Anonymous Monk on Nov 13, 2021 at 17:54 UTC

    Respected monks

    Thank you for your advice. Yes I should have checked existing threads, but I did not. Sorry. However, your answers were quite eye opening. Thank you. The advice of focusing on refreshing Perl and learning a tiny bit of Python everyday seems like a good suggestion. I'm currently installing Linux on my personal laptop hence will not be able to post links immey but I'll try to search and post them. once I find them. Thank you again Monks.

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11138774]
Approved by talexb
Front-paged by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2022-05-22 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (80 votes). Check out past polls.

    Notices?