[Israel.pm] One-liner perl question

Avishalom Shalit avishalom at gmail.com
Mon Sep 10 14:27:04 PDT 2012


just one minor change,
this smells much better

 perl -le '$counter[length($_)]++    or      $ARGV[0]-- > 0    and
print      for sort       {length($a) <=> length($b)}
@ARGV[1..$#ARGV]; ' 4 *

-----

while i am at it ,
here is a small [OT] project i am working on,
be happy to hear comments.
http://eppur-si.appspot.com/

-- vish



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


More information about the Perl mailing list