News for hackers. Stuff that matters.
Re:10 tips for writing perl one-liners by jrockway on Thursday May 27, 2010 @12:10PM (#1384075)
Perl is dead. One-liners are unmaintainable. Everyone should write their one-off command invocations with test driven development, separation of interface and implementation, javadoc, and aspect-oriented programming.
Re:10 tips for writing perl one-liners by pellicle on Thursday May 27, 2010 @12:57PM (#1384231)
I don't think HN's sarcasm tags are rendering correctly today.
Re:10 tips for writing perl one-liners by gamache on Thursday May 27, 2010 @01:01PM (#1384240)
I think we could really use a Ruby DSL for naysaying.
Re:10 tips for writing perl one-liners by zavulon on Thursday May 27, 2010 @05:50PM (#1385031)
I guess it's "in style" now to make fun of "Perl is unmaintainable" statements. Sure, it's cool and a lot of fun, until you're the one that has to maintain it and make changes to it.
Re:10 tips for writing perl one-liners by jrockway on Thursday May 27, 2010 @06:01PM (#1385059)
I maintain a lot of Perl. It's a joy.

Now this legacy C++ and Java... hoo boy...

Re:10 tips for writing perl one-liners by pkrumins on Thursday May 27, 2010 @11:55AM (#1384006)
Also see my article on "Perl One-Liners Explained":

http://www.catonmat.net/blog/perl-one-liners-explained-part-...

Re:10 tips for writing perl one-liners by sigzero on Thursday May 27, 2010 @03:03PM (#1384617)
I have! I liked it very much. I was using a Perl dos2unix one liner this morning in fact. I love Perl.
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).
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 ;)
Re:10 tips for writing perl one-liners by wazoox on Thursday May 27, 2010 @05:07PM (#1384953)
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;
  }
Re:10 tips for writing perl one-liners by sreque on Thursday May 27, 2010 @01:48PM (#1384411)
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.
Re:10 tips for writing perl one-liners by zrail on Thursday May 27, 2010 @04:09PM (#1384804)
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.

[1]: http://invisible-island.net/mawk/mawk.html

Re:10 tips for writing perl one-liners by devinj on Thursday May 27, 2010 @09:28PM (#1385423)
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.
Re:10 tips for writing perl one-liners by d0mine on Thursday May 27, 2010 @05:51PM (#1385035)
`END{ }` could be replace by eskimo operator `}{`:

  perl -F, -lane '$t += $F[1]; }{ print $t'
http://www.perlfoundation.org/perl5/index.cgi?eskimo_operato...

`..` is called flip-flop in the context describe in the post.

Goatse operator `=()=`:

  my $count_vowels =()= /[aeiou]/g;
Here's another usage for `\K`:

  echo '/a/b/c/def/gh' | perl -lnE'$d{$`}++while/\w\K\b/g }{$,=" ";say keys%d'
Output:

  /a/b/c/def/gh /a/b/c /a/b/c/def /a/b /a
http://stackoverflow.com/questions/2892126/file-fix-it-codeg...

Other features: http://stackoverflow.com/questions/161872/hidden-features-of...

Re:10 tips for writing perl one-liners by vtail on Thursday May 27, 2010 @01:19PM (#1384306)
Tricks 1-7 are also supported by Ruby - it accepts the same command-line options with the same functionality.
Re:10 tips for writing perl one-liners by telemachos on Thursday May 27, 2010 @04:54PM (#1384921)
A good collection of articles, tutorials and slide-shows on Perl one-liners, all in one place:

http://bufferfly.members.winisp.net/Perl_oneLiners.html

(I remember especially liking the one from Sial.org - a lot of good Perl content on that site, the two from Cultured Perl and the FMTYEWTK on mass edits.)

Re:10 tips for writing perl one-liners by chrismealy on Thursday May 27, 2010 @11:59AM (#1384026)
I didn't know about \K and -MRegexp::Common. I liked the explanation of '..' too. Thanks.
Re:10 tips for writing perl one-liners by absconditus on Thursday May 27, 2010 @09:40PM (#1385435)