guest@mukunda.com:/blog# ./cat 2022/learn-perl.txt
Name: Learn Perl
Date: July 17th, 2022
This weekend I sat down and learned Perl, or at least a
workable subset that I could pick up in a day.
Earlier, I was writing a script in bash, and, while writing
a particular tedious string of piped commands, I considered
briefly what alternatives there might be.
I mean, look at this thing:
db_dump_latest=$(aws --profile "$AWS_PROFILE" s3 ls s3://$binstore_bucket/$instance_id/ |
grep -oE "PRE sbsdb_dump_(.*)" |
sed 's#PRE sbsdb_dump_\(.*\)/#\1#' |
sort -n | tail -n 1)
I know that some people out there are quite good at golfing
in the bash field, but personally I prefer a bit more
ubiquity between logic descriptions--you know, operations
that you can read easily.
Python I would say is king, but I noted that Perl is also
stocked in nearly every Linux distro along with a standard
set of useful libraries.
Perl is a happy medium between the commandline and a general
programming language, with builtin syntax for performing
shell commands or parsing strings with regex.
Regex support was one of the things that stuck out to me.
Perl is famous for it. With so many practical uses,
shortcuts to work with regexes are great. For example:
if (`hostnamectl` =~ /Operating System: (Ubuntu 20.*)/) {
print("OS: $1\n");
print("Running on Ubuntu 20.x!\n");
}
Backticks are especially convenient. I find `cat filename`
more preferable than using the standard I/O libraries to
read a file.
There is still some cruft here and there, like the rules for
references or awkward syntax and behavior for elementary
programming constructs, much like any language from yore,
but it wasn't difficult at all to get the hang of it and
finish a small project.
Overall, I still think Python is the best for system
scripting, but Perl's availability, unique conveniences, and
ease of learning is well worth your time.
I just hate bash.
Send the author a comment
<< Index