Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Need help in sorting the array

by bv (Friar)
on Dec 10, 2009 at 15:06 UTC ( #812210=note: print w/replies, xml ) Need Help??


in reply to Need help in sorting the array

I believe this calls for an application of the GRT (untested):

my @newArr = map { # put it all back together join '', @$_ } sort { # dereference and sort numerically by 2nd element $a->[1] <=> $b->[1] } map { # break off the digits and put in an anonymous array [ split /(\d+)/ ] } @arr;

@_=qw; Just another Perl hacker,; ;$_=q=print "@_"= and eval;

Replies are listed 'Best First'.
Re^2: Need help in sorting the array
by johngg (Canon) on Dec 10, 2009 at 15:25 UTC
    I believe this calls for an application of the GRT (untested):

    Actually, what you have there is a ST (http://en.wikipedia.org/wiki/Schwartzian_transform). A GRT (http://www.sysarch.com/Perl/sort_paper.html) is characterised by having a simple lexical sort rather than requiring a routine. Like this:

    $ perl -le ' > @arr = qw{ TEXT1 TEXT3 TEXT11 TEXT2 TEXT13 }; > print for > map { substr $_, 9 } > sort > map { sprintf q{%09d%s}, ( split m{(?<=[A-Z])(?=\d)} )[ 1 ], $_ +} > @arr;' TEXT1 TEXT2 TEXT3 TEXT11 TEXT13 $

    I hope this is of interest.

    Cheers,

    JohnGG

    Update: Added references.

      I always get those confused! Someday I'll learn, or at least learn to look it up before I post.


      @_=qw; Just another Perl hacker,; ;$_=q=print "@_"= and eval;
      Thanks a lot guys !!! this is hepful

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2019-12-15 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?