develooper Front page | perl.perl6.users | Postings from June 2018

Re: need sort help

Thread Previous | Thread Next
From:
Brandon Allbery
Date:
June 9, 2018 04:17
Subject:
Re: need sort help
Message ID:
CAKFCL4VmUvs+vCZ4G0F4J6Cjer+UVsU2fsS9ydgEDYJOcUHNoQ@mail.gmail.com
You didn't use what I sent. It's $^x and $^y, not $a and $b.

(Aside: I *really* wish placeholders didn't work that way; this thread is
demonstrating why it's a bad idea. Not to mention a pain in the butt.)


On Sat, Jun 9, 2018 at 12:12 AM ToddAndMargo <ToddAndMargo@zoho.com> wrote:

> >>> @x.sort: {
> >>>    my $a = $^x ~~ m:g/\d+/;
> >>>    my $b = $^y ~~ m:g/\d+/;
> >>>    $a[6].defined cmp $b[6].defined
> >>>    ??
> >>>      $a[3] cmp $b[3]
> >>>    || $a[1] cmp $b[1]
> >>>    || $a[2] cmp $b[2]
> >>>    || $a[4] cmp $b[4]
> >>>    || $a[5] cmp $b[5]
> >>>    || $a[6] cmp $b[6]
> >>>    || $x cmp $y
> >>>    !! $x cmp $y
> >>> };
> >>
> >> On Fri, Jun 8, 2018 at 11:53 PM ToddAndMargo <ToddAndMargo@zoho.com
> >> <mailto:ToddAndMargo@zoho.com>> wrote:
> >>
> >>     On 06/08/2018 07:00 PM, Brent Laabs wrote:
> >>      > let me revise that
> >>      >
> >>      > @x.sort: {
> >>      >    my $a = $^a ~~ m:g/\d+/;
> >>      >    my $b = $^b ~~ m:g/\d+/;
> >>      >    $a[6].defined cmp $b[6].defined
> >>      >    ??
> >>      >      $a[3] cmp $b[3]
> >>      >    || $a[1] cmp $b[1]
> >>      >    || $a[2] cmp $b[2]
> >>      >    || $a[4] cmp $b[4]
> >>      >    || $a[5] cmp $b[5]
> >>      >    || $a[6] cmp $b[6]
> >>      >    || $^a cmp $^b
> >>      >    !! $^a cmp $^b
> >>      > };
> >>      >
> >>
> >>
> >>     $   ls | perl6 -e 'my @x=slurp(); @x.sort: { my $a = $^a ~~
> m:g/\d+/;my
> >>     $b = $^b ~~ m:g/\d+/;$a[6].defined cmp $b[6].defined ?? $a[3] cmp
> $b[3]
> >>     || $a[1] cmp $b[1] || $a[2] cmp $b[2] || $a[4] cmp $b[4]  || $a[5]
> cmp
> >>     $b[5]  || $a[6] cmp $b[6] || $^a cmp $^b !! $^a cmp $^b a cmp $^b'
> $^a
> >>     cmp $^b
> >>     ===SORRY!=== Error while compiling -e
> >>     Redeclaration of symbol '$^a' as a placeholder parameter
> >>     at -e:1
> >>     ------> my @x=slurp(); @x.sort: { my $a = $^a⏏ ~~ m:g/\d+/; my $b =
> $^b
> >>     ~~ m:g/\d+/;$a
>
> On 06/08/2018 09:03 PM, Brandon Allbery wrote:
> > Brent thinkoed that slightly. (Forgot that first use of a placeholder
> > "declares" it, and thereafter you don't use the ^. Which then collides
> > with the local "my" variables.)
> >
>
>
> $   ls | perl6 -e 'my @x=slurp(); @x.sort: { my $a = $a ~~ m:g/\d+/; my
> $b = $b ~~ m:g/\d+/;$a[6].defined cmp $b[6].defined ?? $a[3] cmp $b[3]
> || $a[1] cmp $b[1] || $a[2] cmp $b[2] || $a[4] cmp $b[4]  || $a[5] cmp
> $b[5]  || $a[6] cmp $b[6] || $^a cmp $^b !! $^a cmp $^b a cmp $^b' $^a
> cmp $^b
> ===SORRY!=== Error while compiling -e
> Cannot use variable $a in declaration to initialize itself
> at -e:1
> ------> my @x=slurp(); @x.sort: { my $a = $⏏a ~~ m:g/\d+/; my $b = $b ~~
> m:g/\d+/;$a
>      expecting any of:
>          term
>


-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About