[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: more on 1 liner perl/awk



On Mon, Mar 10, 2003 at 09:18:05PM +0000, Colin Watson wrote:
> Then there are the usual tricks of eliminating whitespace and so on. In
> fact, all the whitespace in the arguments to perl in the line above can
> be removed if you feel so inclined:
> 
>   perl -lane'print$F[2]if$F[1]eq"1957"' < mat.txt
> 
> Shorter solutions may be possible.

Oh, you can save another character by taking advantage of the automatic
conversions between numbers and strings in Perl. If you want to keep it
whitespace-free, the standard trick is to use unary +, which is always a
no-op except for its useful syntactical effects:

  perl -lane'print$F[2]if$F[1]eq+1957' < mat.txt

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: