Why use Perl instead of Python?
Because Perl is a more expressive language and also has the best regex implementation. It has also being the defacto system script language readily available in unix environment. Perl can be written in concise and terse manner, making it very suitable to mix in a shell script.
Perl is also available as modperl, which currently is still tightly integrated with Apache HTTPd, which makes it an ideal dynamic configuration subsystem as well as a web scripting language.
Here is a seemingly cryptic sample code I wrote as a demonstration to convert from fixed length file input into CSV
Perl:
@_=$_=~/(.{4})(.{8})(.{10})/; s/"/""/g,s/\s*$//,s/^\s*// foreach (@_); print "\"",join("\",\"",@_),"\"\n"
Bash:
$ echo -e "COL1COL2 COL3 \nA\"AABB BB CCCCCCCCCC" | perl -ne '@_=$_=~/(.{4})(.{8})(.{10})/; s/"/""/g,s/\s*$//,s/^\s*// foreach (@_); print "\"",join("\",\"",@_),"\"\n"'
"COL1","COL2","COL3"
"A""AA","BB BB","CCCCCCCCCC"
I also use one-liner perl a lot in my work, for eg, to allow me parse log files to easily focus in the shell.
Here is a fragment of the httpd access logs
Code:
[02/Aug/2021:14:36:43 +0800] "GET /some_path/ HTTP/1.1" 200 RT=1002ms
If I want to see all web requests that are more than 1s, I may so do in the command line as such
Perl:
tail -f /var/log/httpd/access_log | perl -ne '/RT=(\d+)ms/; print if ($1 > 1000)'
If you are someone like me whom like programming languages for its constructs and concept, you will like Perl. I am not aware if there is another language that is as "interesting" as Perl. There are a lot of quirks about it, and I like its quirks. Perl is not one important language to me, it's one of the many languages I use in my work. I like to work with an arsenal of tools and mix and match among them. It's very often I use grep, awk, sed, perl, bash , jq, python, and other tools altogether to get a piece of work done. I don't need to find a strong reason to do so, I give myself the freedom to have options.
References:
https://blog.usejournal.com/what-is-perl-how-relevant-it-is-and-how-to-get-started-d802e7aba2cdhttps://www.activestate.com/blog/top-10-programming-tasks-that-perl-is-used-for/