<div dir="ltr">so cool ... didn't think about storing them all and printing out just the unique<br><br>Anyhow thanks everyone for the help and good ideas<br><br>Ynon<br><br><br><div class="gmail_quote">On 10 September 2012 15:57, Avishalom Shalit <span dir="ltr"><<a href="mailto:avishalom@gmail.com" target="_blank">avishalom@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">here you go.<br>
<br>
perl -e 'map{$counter[length($_)]++ or $ARGV[0]-- > 0 and print "$_<br>
"}sort{length($a) <=> length($b)} @ARGV[1..$#ARGV]; ' 5 *<br>
<br>
but why oh why oh why ?<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On 10 September 2012 11:36, ynon perek <<a href="mailto:ynonperek@gmail.com">ynonperek@gmail.com</a>> wrote:<br>
> Awesome - but can it be done in a single statement ? (like the string-based<br>
> solution)<br>
><br>
><br>
> On 10 September 2012 08:48, Micha <<a href="mailto:mickey75@gmail.com">mickey75@gmail.com</a>> wrote:<br>
>><br>
>> Ynon's requirement was no duplicates in length.<br>
>> this works for me:<br>
>><br>
>> $ perl -e<br>
>> 'my$x=+{map{length($_)=>$_}reverse(glob("*"))};print($x->{$_}."\n")for(splice(@{[sort{$a<=>$b}keys<br>
>> %$x]},0,shift))' 9<br>
>><br>
>> cheers,<br>
>> Micha<br>
>><br>
>><br>
>> On Mon, Sep 10, 2012 at 12:43 AM, Avishalom Shalit <<a href="mailto:avishalom@gmail.com">avishalom@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> remember that TLAP (talk like a pirate) day is soon<br>
>>><br>
>>> @ARRRRGV<br>
>>><br>
>>><br>
>>><br>
>>> well to be honest , since the list isn't that long it could have been<br>
>>> a flat sort<br>
>>> a bit cleaner<br>
>>><br>
>>> >> $ perl -e '$n=$ARGV[0];@a=sort{length($a)<=> length($b)}<br>
>>> >> @ARGV[1..$#ARGV]; print "@a[0..$n]"' 4 *<br>
>>><br>
>>><br>
>>> -- vish<br>
>>><br>
>>><br>
>>><br>
>>> On 9 September 2012 23:35, sawyer x <<a href="mailto:xsawyerx@gmail.com">xsawyerx@gmail.com</a>> wrote:<br>
>>> > I can recognize a Schwarzian transform when I see one!<br>
>>> ><br>
>>> ><br>
>>> > On Mon, Sep 10, 2012 at 1:06 AM, Avishalom Shalit <<a href="mailto:avishalom@gmail.com">avishalom@gmail.com</a>><br>
>>> > wrote:<br>
>>> >><br>
>>> >> $ perl -e '$n=$ARGV[0];@a=map{$_->[1]}sort{$a->[0] <=><br>
>>> >> $b->[0]}map{[length($_),$_]} @ARGV[1..$#ARGV]; print "@a[0..$n]"' 4 *<br>
>>> >><br>
>>> >> clarifying<br>
>>> >><br>
>>> >> $ perl -e '<br>
>>> >> $n=$ARGV[0];<br>
>>> >> @a=map{$_->[1]}<br>
>>> >> sort{$a->[0] <=> $b->[0]}<br>
>>> >> map{[length($_),$_]}<br>
>>> >> @ARGV[1..$#ARGV];<br>
>>> >> print "@a[0..$n]"' 4 *<br>
>>> >><br>
>>> >><br>
>>> >> -- vish<br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >><br>
>>> >> On 9 September 2012 18:39, ynon perek <<a href="mailto:ynonperek@gmail.com">ynonperek@gmail.com</a>> wrote:<br>
>>> >> ><br>
>>> >> > Hi All,<br>
>>> >> ><br>
>>> >> > I'm trying to turn a short program into a one-liner. The program<br>
>>> >> > takes<br>
>>> >> > an argument "n" and prints the first n file names sorted by file<br>
>>> >> > name<br>
>>> >> > length, with no duplicates in length.<br>
>>> >> ><br>
>>> >> > Here's what I wrote for the original code:<br>
>>> >> > <a href="https://gist.github.com/3684778" target="_blank">https://gist.github.com/3684778</a><br>
>>> >> ><br>
>>> >> > The part I found difficult is to sort a dictionary by its keys, and<br>
>>> >> > print the top n values...<br>
>>> >> ><br>
>>> >> > Ideas ?<br>
>>> >> ><br>
>>> >> > (clarification: this is just for fun, nothing important, and I'm not<br>
>>> >> > interested in string based solutions, already got one on the same<br>
>>> >> > gist).<br>
>>> >> ><br>
>>> >> > Cheers,<br>
>>> >> > Ynon<br>
>>> >> ><br>
>>> >> > --<br>
>>> >> ><br>
>>> >> > כותב הרצאות ? מדבר מול קהל ? הבלוג שלי לומד לדבר כתוב במיוחד בשבילך.<br>
>>> >> ><br>
>>> >> ><br>
>>> >> > _______________________________________________<br>
>>> >> > Perl mailing list<br>
>>> >> > <a href="mailto:Perl@perl.org.il">Perl@perl.org.il</a><br>
>>> >> > <a href="http://mail.perl.org.il/mailman/listinfo/perl" target="_blank">http://mail.perl.org.il/mailman/listinfo/perl</a><br>
>>> >> _______________________________________________<br>
>>> >> Perl mailing list<br>
>>> >> <a href="mailto:Perl@perl.org.il">Perl@perl.org.il</a><br>
>>> >> <a href="http://mail.perl.org.il/mailman/listinfo/perl" target="_blank">http://mail.perl.org.il/mailman/listinfo/perl</a><br>
>>> ><br>
>>> ><br>
>>> ><br>
>>> > _______________________________________________<br>
>>> > Perl mailing list<br>
>>> > <a href="mailto:Perl@perl.org.il">Perl@perl.org.il</a><br>
>>> > <a href="http://mail.perl.org.il/mailman/listinfo/perl" target="_blank">http://mail.perl.org.il/mailman/listinfo/perl</a><br>
>>> _______________________________________________<br>
>>> Perl mailing list<br>
>>> <a href="mailto:Perl@perl.org.il">Perl@perl.org.il</a><br>
>>> <a href="http://mail.perl.org.il/mailman/listinfo/perl" target="_blank">http://mail.perl.org.il/mailman/listinfo/perl</a><br>
>><br>
>><br>
>><br>
>> _______________________________________________<br>
>> Perl mailing list<br>
>> <a href="mailto:Perl@perl.org.il">Perl@perl.org.il</a><br>
>> <a href="http://mail.perl.org.il/mailman/listinfo/perl" target="_blank">http://mail.perl.org.il/mailman/listinfo/perl</a><br>
><br>
><br>
><br>
><br>
> --<br>
><br>
> כותב הרצאות ? מדבר מול קהל ? הבלוג שלי לומד לדבר כתוב במיוחד בשבילך.<br>
><br>
><br>
> _______________________________________________<br>
> Perl mailing list<br>
> <a href="mailto:Perl@perl.org.il">Perl@perl.org.il</a><br>
> <a href="http://mail.perl.org.il/mailman/listinfo/perl" target="_blank">http://mail.perl.org.il/mailman/listinfo/perl</a><br>
_______________________________________________<br>
Perl mailing list<br>
<a href="mailto:Perl@perl.org.il">Perl@perl.org.il</a><br>
<a href="http://mail.perl.org.il/mailman/listinfo/perl" target="_blank">http://mail.perl.org.il/mailman/listinfo/perl</a></div></div></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div dir="rtl"><br>כותב הרצאות ? מדבר מול קהל ? הבלוג שלי <a href="http://publicspeakr.blogspot.com/" target="_blank">לומד לדבר</a> כתוב במיוחד בשבילך.<br>
</div></div><br>
</div>