Hacker News new | past | comments | ask | show | jobs | submit login
Famous Perl One-Liners Explained, Part II: Line Numbering (catonmat.net)
39 points by Anon84 on July 31, 2009 | hide | past | favorite | 6 comments



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.


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.


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.


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.


See also "Area Number Three" in http://steve.yegge.googlepages.com/five-essential-phone-scre...

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.


...but if any of my employees wrote this kind of write-only code, I'd fire them.

It's possible you're actually not aware, so take this in the spirit it's intended: statements like this make you sound like a colossal blow-hard.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: