On 09/11/2012 05:23 PM, Assaf Gordon wrote:

Here's another solution, even shorter (if you're willing to accept mixing ls, shell pipes and perl):
===
ls | perl -sne '$a{length($_)}=$_;END{map{print $a{$_}}(1..$N+1)}' -- -N=5
===


FINALLY, a one-liner that uses a perl flag other than -e!

Although it generates different output than the other programs - with file names that have identical length, it prints the last, not the first (alphabetically) - so it should probably be $a{length($_)}||=$_

The big bug is it doesn't actually print the first N file names, it prints the file names with lengths between 1..N
So if the shortest name is more than 1 character, or some slots are missing...






--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to