4 ms·
In this day and age, with Python and all, is Perl still worth learning?
by catacombs 8y ago
In this day and age, with Python and all, is Perl still worth learning?
- Zhyl 8y agoIt's worth getting a few insights into what it does well. As with any language it _can_ do anything, but a few key features that made it stand out for me: * Perl is set up for really terse one-liners. You can basically emulate or surpass most Unix tools with only a cursory knowledge of the syntax * Perl syntax is highly geared towards text processing and regular expressions. File handling and regexes are so much quicker and easier to use than Python. If I were in a situation where I had a bunch of files I needed to process and the task didn't easily fall into something that could be done with a bash command, I'd probably reach for perl over python for a quick and dirty disposable script.
- catacombs 8y ago> * Perl is set up for really terse one-liners. You can basically emulate or surpass most Unix tools with only a cursory knowledge of the syntax This definitely interests me. How does perl surpass Unix tools? I guess perl has the benefit of handling the equivalent of sed and awk.
- Zhyl 8y agoYeah, it has equivalents for each. Sed: perl -pe 's/foo/bar/' file1 Grep: perl -pe '/foo/' file1 uniq: perl -ne 'print unless $seen{$_}++' file1 But then you can combine conditions: perl -ne 's/foo/bar/ if /baz/ && /yot/; print "Line number $. changed to $_"' file1 And do some awk-ish line splitting: perl -F, -ane '$sum += $F[2]; END{ print "The sum of column 3 is $sum" }' file1 It absolutely flies in the face of the unix philosophy and is much more complicated than picking up each tool individually, but once you get to grips with 'em they're very handy.
- a_bonobo 8y agoThis blew my mind recently, when I had to delete millions of files in a directory and rm didn't make the cut (too many arguments), and find -delete took forever: https://unix.stackexchange.com/a/79656 https://unix.stackexchange.com/a/79656 perl -e 'for(<*>){((stat)[9]<(unlink))}' seems to be the fastest possible way to delete enormous amounts of files
- mkl 8y agoDid you try xargs, to do groups of files at once? That's what I usually do: find -type f -print0 | xargs -0 rm
- marcosdumay 8y agoPeople keep saying Perl6 is great, and I have no reason to think it's any worse than Python (but I don't know it). One may also want to learn Perl5 for dealing with legacy stuff (either keeping or getting rid of it). There is a lot of it out there.
- kamaal 8y agoYes, if you don't want to be forced to write exception handling and doing a dozen different tricks for merely writing and using one single regular expression. A lot of forced indentation and absence of braces, and absence of sigils makes it harder to read Python scripts. However that's not the only problem with Python. If you are scripting you want the regular `unix_command` command thingy to work fine. More-so you want to read the output of that thing using a syntax like my @command_output = `unix_command`; You also want heredocs. And you want multiline anonymous functions. I could go on and on. But Python seems to be more like a tool trying to compete with Java than Perl.