Re:10 tips for writing perl one-liners
by devinj on Thursday May 27, 2010 @12:34PM
(#1384157)
I think this article has convinced me that I should learn Perl. Looks bloody useful for shell scripts, indeed ("a better awk" is the phrasing I've heard).
[ Parent
| on HN ]
Re:10 tips for writing perl one-liners
by someone_here on Thursday May 27, 2010 @01:00PM
(#1384235)
It's kind of like a gateway drug once you find out about CPAN ;)
It's definitely better than shell for quick file processing :) Check out this fantastic cut replacement (thanks to mjd):
#!/usr/bin/perl
my $field = shift or usage();
$field -= 1 if $field > 0;
while (<>) {
chomp;
my @f = split;
print $f[$field], "\n";
}
sub usage {
print STDERR "$0 fieldnumber\n";
exit 1;
}No one will argue with you that Perl isn't better than awk, if that's the bar you've set for yourself for picking a new language to learn.
I use perl every day and awk almost every day. Awk is useful for commands where it forms a small part of an overall pipeline and needs to be somewhat terse, and yet fast. Gawk is actually fairly fast, mawk[1] even more so.
Well, there are languages I learn to improve my mind, and to improve my craft. As far as the mind goes, perl is nothing new (on the mind to-learn list: Haskell, OCaml, Eiffel, Erlang). Craftwise, it looks very useful.