Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Sorting path like strings

by BrowserUk (Patriarch)
on Jan 05, 2006 at 08:46 UTC ( [id://521140]=note: print w/replies, xml ) Need Help??


in reply to Sorting path like strings

If your numeric values are all less than 255, then this works. You could swap the ST to a GRT or OM if performance is a concern. If your numbers get larger than 255 you could probably use unicode pack 'U*', but I haven't tested that.

@data = qw[ 0/1/2/3 0 0/4/5/6 0/4 0/1 0/1/2 0/4/5 0/10/111/145 0/10/111 0/10 ];; print for map{ $_->[0] } sort{ $a->[1] cmp $b->[1] } map{ [ $_, pack 'C*', split '/', ] } @data;; 0 0/1 0/1/2 0/1/2/3 0/4 0/4/5 0/4/5/6 0/10 0/10/111 0/10/111/145

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Sorting path like strings
by arkturuz (Curate) on Jan 05, 2006 at 13:34 UTC
    How do you print newlines ("\n") here?

      My perl shell has the -l switch on the shebang line which means amongst other things) that print statements have a newline appended to them automatically. See perlrun for the details.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Hm, I meant in the program.

        And after thinking I found it:

        print for map{ $_->[0] . "\n" } etc.
        I should think a lot more before posting a trivial questions. :-)
Re^2: Sorting path like strings
by Aristotle (Chancellor) on Jan 05, 2006 at 13:47 UTC

    Are you sure that non-C locales won’t cause this to sort in orders other than ASCIIbetical (and thus wrongly), particularly if you add Unicode to the mix?

    Makeshifts last the longest.

      Are you sure that non-C locales won’t cause this to sort in orders other than ASCIIbetical

      Um, no. Did I imply that I was?

      I assume that anyone using non-C locales will know they are and know that they will have to take special steps to get sorts to operate correctly. This assumption is based upon the fact that many uses of GRT (including yours elsewhere in the thread), and as far as I can tell from looking, many of the various sorting modules on CPAN will be similarly affected.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found