The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 04-22-2009
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
Quote:
Originally Posted by dangral View Post
Thanks. I figured it out.

Code:
sub Bysite {
    if ( $a =~ /^0[SV]/ ) {
        return -1;
    }
    elsif ( $b =~ /^0[SV]/ ) {
        return 1;
    }
    lc($a) cmp lc($b);
}

@array = sort Bysite @array;
Thats a good solution but it will not sort your sample array into what you posted:

0S09
0S22
0V54
0V72
0A13
0H98
0L43
EL24
STB45

it sorts a little differently:

0S22 <--
0S09 <--
0V54
0V72
0A13
0H98
0L43
EL24
STB45

but maybe close enough is OK