[Top][All Lists]

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

Re: sort by line length

From: Brian Dessent
Subject: Re: sort by line length
Date: Tue, 24 Apr 2007 06:14:18 -0700

Jim Meyering wrote:

> You can do this in perl (or awk, ruby, etc) as a one-liner,
> so it may not be worth adding to a C application:
> echo 1 938 four aa aaaaa | fmt -1 \
>   | perl -ne 'push @line, $_;sub END{print sort {length $a<=>length $b} 
> @line}'
> 1
> aa
> 938
> four
> aaaaa

Not to derail on perl golfing but how about just:

$ perl -e 'print sort {length($a)<=>length($b)} <>' file


reply via email to

[Prev in Thread] Current Thread [Next in Thread]