I am attempting to sort data which has  a combination of both numeric
and alpah numeric data. Now it would not be so bad, but the numeric data
can be either 9 or 10 characters in length and no leading zero is
supplied in the numbers.

I have supplied some code I am playing with, but running into a mental
block in attempting to get it sorted.

        Any thoughts on how to approach would be greatly appreciated?
Running on XP AS 5.8.8.Build 820. Trying to use core Perl verses adding
any modules if possible.

#!perl

use strict;
use warnings;
my %MPI = ();
my $MyProInfo = \%MPI;

my $MyIn = 0;
my $MyOut = 0;

my $MyWrkKey;
while ( <DATA> ) {
    chomp;
    $MyIn++;
    next if ( /^\s*(#|$)/ );
    next if ( /^\s/ );
    $MyWrkKey = substr($_,0,13);
    $MyProInfo->{$MyWrkKey} = 1;
    $MyOut++;
 }

{
    my $MyPrtKey;
    foreach $MyPrtKey ( sort { $a->[1] <=> $b->[1] ||
                               $a->[0] cmp $b->[0]
                              }
                        map{[$_, /^[a-z]/i ? 0 : 1 ]}
                        keys %{$MyProInfo}
                       ) {
        printf "MyPrtKey: %s\n",
                                $MyPrtKey->[0];
     }
 }
__DATA__
#
#   actual number or alpha is in positions 1 to 10 and when numeric can
be all ten
#   Would like to do a true numeric sort on the numbers and alpha sort
on the alpha
#
075991200 000 prod   0000440.32   000003387    0148          Y
Y      0148
0964844694000 prod   0000065.56   000000042    0001          Y
Y      0001
0964928823000 prod   0000059.36   000000030    0001          Y
Y      0001   
990028300 000 xxxx   0000064.98   000000041    0001          Y
Y      0001
990028318 000 xxxx   0000064.98   000000041    0001          Y
Y      0001
990032732 000 xxxx   0000051.84   000000047    0001          Y
Y      0001
ALN-218435000 xxxx   0000046.35   000000029    0001          Y
Y      0001
ALN-244079000 xxxx   0000047.36   000000046    0001          Y
Y      0001
^------ Code ends here

     Thanks.

  Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449           FAX
http://fedex.com/us 


**********************************************************************
This message contains information that is confidential and proprietary to FedEx 
Freight or its affiliates.  It is intended only for the recipient named and for 
the express  purpose(s) described therein.  Any other use is prohibited.
**********************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to