A short Perl example
Archive - Originally posted on "The Horse's Mouth" - 2008-07-30 00:11:42 - Graham Ellis#!/usr/bin/perl -pa
$_ = "$F[0] $F[-2]\n";
What does that Perl code do?
Although it's very short, it's also somewhat obscure, and my delegates yesterday were not at all sure that they would wish to be given code like this to maintain ... but then they admitted that they have seen things like this around ...
There are some Perl programmers who take what I feel is a perverse delight in writing their code as short as possible, even to the extent that it looses clarity; for sure, you should make good use of the Perl language and its facilities to avoid needless loops - use a grep in place of a foreach loop with a regular expression check and a push, and slurp a file into a list by all means rather that reading in through a while loop - but the above takes it just too far!
Oh - I asked you what it does, didn't I? It reads the file named on the command line in line by line, and prints out the first and next-to-last field on each line, throwing away the rest of the data.