Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^4: Custom Sort An AoA

by LanX (Canon)
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)

update

something like

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


Comment on Re^4: Custom Sort An AoA
Select or Download Code
Re^5: Custom Sort An AoA
by Limbic~Region (Chancellor) on Apr 02, 2014 at 12:11 UTC
    LanX,
    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1080624]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2014-10-26 00:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls