Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^4: Custom Sort An AoA

by LanX (Bishop)
on Apr 01, 2014 at 18:42 UTC ( #1080624=note: print w/replies, xml ) Need Help??

in reply to Re^3: Custom Sort An AoA
in thread Custom Sort An AoA

I'd do it too with an extra helper function, but I would keep the first condition out (for readability, flexibility and reuse)

something like

sub cmp_vec { # return either -1,0 or 1 comparing over two equally sized arrays } sort { @$a <=> @$b or cmp_vec($a,$b) } @list;

for full flexibility a cmp-function could be passed as call-back in third position.

As a side note, I'm not sure if this could be done with Perl6 Meta ops, something like @a >>cmp<< @b (after reversing of course).

Cheers Rolf

( addicted to the Perl Programming Language)


something like

sub cmp_vec { my ($a,$b) = @_; for (reverse 0.. @$a-1) { if (my $x= $a->[$_] cmp $b->[$_]) { return $x } } return 0; ]

Replies are listed 'Best First'.
Re^5: Custom Sort An AoA
by Limbic~Region (Chancellor) on Apr 02, 2014 at 12:11 UTC
    You may be amused to know that this question is being used to help me identify and organize execution paths through 6502 Assembly. (See also my response to shmem).

    Cheers - L~R

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1080624]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2018-06-20 21:48 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.