Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > Sort Alpha Array

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-11-04, 19:50
ulloita ulloita is offline
Registered User
 
Join Date: May 2004
Posts: 5
Sort Alpha Array

Hi!!
I have a little problem
I want to sort an alphanumerical array:
For example:
("A10","A1","A20","A2","A11","AB1","A19","A32","A3 ","B5","B10","AF5")
sorted array will be:
("A1","A2","A3","A10","A11","A19","A20","A32","AB1 ","AF5","B5","B10")
How can i do that???
Thanks a lot
Reply With Quote
  #2 (permalink)  
Old 06-21-04, 01:09
senza_nome senza_nome is offline
Registered User
 
Join Date: Jun 2004
Location: Nowhere Near You
Posts: 89
The way I read it, you want to "break" the "value" into two components - an alpha component and a numeric component. The values are to be ordered alphabetically with respect to the alpha components and numerically with respect to the numeric components. Is this correct?
Reply With Quote
  #3 (permalink)  
Old 06-21-04, 16:28
senza_nome senza_nome is offline
Registered User
 
Join Date: Jun 2004
Location: Nowhere Near You
Posts: 89
This what you want?

Code:
my(@out)=sort { my($aA,$aN,$bA,$bN); if ($a =~ /([a-zA-Z]+)(\d+)/) { $aA=$1;$aN=$2;}; if ($b =~ /([a-zA-Z]+)(\d+)/) { $bA=$1;$bN=$2;}; if ($aA lt $bA) { return -1;} elsif ($aA gt $bA) { return 1;} else { return $aN <=> $bN}; } ("A10","A1","A20","A2","A11","AB1","A19","A32","A3","B5","B10","AF5");

Last edited by senza_nome : 06-21-04 at 16:32.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On