On 12/16/05, Wong, Danny H. <[EMAIL PROTECTED]> wrote:> Hi Guys,> I
have an array of values. How can I sort these values that has> a non numeric
character [ _ ] in it? What I did was parse the numbers> before the "_"
character and then perform a number short on those value,> but there must be an
easier way? Any help is greatly appreciated.>> 55_20051202> 56_20051203>
57_20051204> 101_20051205> 59_20051206> 10_20051207> 61_20051208> 62_20051208>
63_20051208> 64_20051209> 65_20051209> 66_20051210> 67_20051211> 68_20051212>
69_20051213> 70_20051214>
Try:
#!/usr/bin/perlmy $k = 0;my %A = ();while(<DATA>){ chomp; ($k = $_) =~
s/_//; $A{$k} = $_ if $_ ne '';}foreach $k (sort {$a<=>$b} keys %A){
print
$A{$k}."\n";}__DATA__55_2005120256_2005120357_20051204101_2005120559_2005120610_2005120761_2005120862_2005120863_2005120864_2005120965_2005120966_2005121067_2005121168_2005121269_2005121370_20051214
Output:10_2005120755_2005120256_2005120357_2005120459_2005120661_2005120862_2005120863_2005120864_2005120965_2005120966_2005121067_2005121168_2005121269_2005121370_20051214101_20051205
The same output if you take numbers before "_" like sorting key.
HTH,--http://vnoss.orgVietnamese Open Source Software Community
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs