Avishalom Shalit wrote, On 09/11/2012 03:39 AM:
> a- you forgot the exclude files of duplicate length bit

The "sort -u" (unique) will ensure each length appears only once.

> 
> also,
> b- perhaps he had a secret part of a program in perl, to which he
> wants to pass an array other than @ARRRRGGV me hearties
> 
> c- i really hope that this was an exercise although my favorite bit of
> perl (written by someone else) is a beautiful dispatch sequence that
> read like a poem
> 

I can't argue about beauty, poems, and secrets desires... 
Technically, I think the shell command answers his request, in a form that is 
shorter (that's a fact) and cleaner (that's my opinion) than the Perl code.

-gordon

 

> 
> 
> On 11 September 2012 02:55, Assaf Gordon <[email protected]> wrote:
>> Hi,
>>
>> On 09/09/2012 01:39 PM, ynon perek wrote:
>>>
>>> I'm trying to turn a short program into a one-liner. The program takes an 
>>> argument "n" and prints the first n file names sorted by file name length, 
>>> with no duplicates in length.
>>>
>>
>> I know you've asked for a *Perl* one-liner, but since a recent suggested 
>> solution already "cheat" by using the shell to get the list of files, why 
>> not just do it entirely in using standard command line programs ?
>>
>> ==
>> ## prints the top 5 longest file names, remove the "r" from sort to print 
>> the shortest.
>> ls | awk '{print length($0), $0}' | sort -nru | cut -f2 -d' ' | head -n5
>> ==
>>
>> Seems cleaner, and shorter than any Perl solution...
>>
>> -gordon
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to