Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
Do you know where your variables are?
 
PerlMonks  

Re: sort by a multiple columns

by CombatSquirrel (Hermit)
on Sep 08, 2004 at 18:03 UTC ( [id://389490]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to sort by a multiple columns

This is really ugly (maybe someone could improve it with pack/unpack), but it reproduces your desired output:
#!perl use strict; use warnings; my @un_sorted = ( [3, 4, 23, 4, 5], [3, 4, 56, 2, 4], [2, 3, 43, 5, 3], [2, 3, 43, 6], [3, 4] ); my $end = chr(1e6); print join "\n", map { join ',', @$_ } map { splice @$_, $#_; $_ } map { [(map(ord, split('', $_)))]} sort map { join('', map chr, @$_) . $end } @un_sorted;
It's a GRT (kinda, probably not the best performance, though). The trick with the end marker is especially ugly, but without it the output would be wrong.
Hope this helped.
CombatSquirrel.

Entropy is the tendency of everything going to hell.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://389490]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.