Perl as a better …
The Endeavour 2013-08-20
Today I ran across Minimal Perl: For UNIX and Linux People. The book was published a few years ago but I hadn’t heard of it because I haven’t kept up with the Perl world. The following chapters from the table of contents jumped out at me because I’ve been doing a fair amount of awk
and sed
lately.:
… 3. Perl as a (better) grep
command 4. Perl as a (better) sed
command 5. Perl as a (better) awk
command 6. Perl as a (better) find
command …
These chapters can be read a couple ways. The most obvious reading would be “Learn a few features of Perl and use it as a replacement for a handful of separate tools.”
But if you find these tools familiar and are not looking to replace them, you could read the book as saying “Here’s an introduction to Perl that teaches you the language by comparing it to things you already know well.”
The book suggests learning one tool instead of several, and in the bargain getting more powerful features, such as more expressive pattern matching. It also suggests not necessarily committing to learn the entire enormous Perl language, and not necessarily committing to use Perl for every programming task.
Regarding Perl’s pattern matching, I could relate to the following quip from the book.
What the only thing worse than not having a particular metacharacter … in a pattern-matching utility? Thinking you do, when you don’t! Unfortunately, that’s a common problem when using Unix utilities for pattern matching.
That was my experience just yesterday. I wrote a regular expression containing \d
for a digit and couldn’t understand why it wasn’t matching.
Most of the examples rely on giving Perl command line options such as -e
so that it acts more like command line utility. The book gives numerous examples carrying out common tasks in grep
etc. and with Perl one-liners. The latter tend to be a little more verbose. If a task falls in the sweet spot of a common tool, that tool’s syntax will be more succinct. But when a task falls outside that sweet spot, such as matching a pattern that cannot be easily expressed with traditional regular expressions, the Perl solution will be shorter.
Related posts:
A little awk Learn one sed command Learn one Perl command