
Famous Perl One-Liners Explained, Part II: Line Numbering - Anon84
http://www.catonmat.net/blog/perl-one-liners-explained-part-two/
======
ccc123ccc
For command line, I prefer awk and sed. Yes, I know they don't have the power
of Perl or Python for big projects, but this is an excellent example of using
a shotgun to kill flies.

Edit: And of course, since this same site has awesome examples of sed and awk
one-liners in action, the comparison has never been easier to make.

~~~
salvadors
For these sorts of examples, I tend to use awk and sed too, but sometimes the
shotgun is useful. One major advantage of using Perl in this context is that
you also have -M, with all of CPAN at your disposal.

------
321abc
One liners like this is why Perl has a reputation of being like line noise.
I'm a big fan of Perl, but if any of my employees wrote this kind of write-
only code, I'd fire them.

~~~
salvadors
If they do any amount of command line wrangling, you should hope that your
employees are writing code like this every day. The whole point of these one-
liners is that once you get the hang of it they're very powerful additions to
your *nix pipeline.

They could write highly maintainable, well tested, peer reviewed etc code to
do the same things, but in this context that would be hugely wasteful, as the
utilities already exist.

This is Perl as a replacement for Awk, not for Java.

~~~
salvadors
See also "Area Number Three" in [http://steve.yegge.googlepages.com/five-
essential-phone-scre...](http://steve.yegge.googlepages.com/five-essential-
phone-screen-questions)

Being able to create that line-noise is, in most cases, significantly more
useful than taking 3 months to create a perfectly engineered recursive phone-
number finding program.

