Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-08-22 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (157 votes), past polls