On Feb 21, Wagner-David said:

>       Key              CPU  Mirror
>         $AUDIT      8     Y
>         $AUDIT1     7     Y
>         $DATA1      7     Y
>         $DATA2      7     Y
>         $DATA3      6     Y

>This data has already been sorted, but I have a couple of disks
>which do not end in a number.  I have the following setup to sort the
>data:
>
>  foreach my $MyKey (
>    sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2] } 
>    map { [ $_, /^([a-z\-]+)(\d*)/i ] }
>    keys %MyDisks
>  ) { ... }
>
>where I have [0] as the key, [1] is alpha portion, [2] is number

>I get two warnings: one for audit above and another for system. Both
>without numbers.
>
>What can be done as it now stands or do I need to break out differently
>(ie, if no numeric add a 0 to the key since I have no zero items?

You could just say

  ($a->[2] || 0) <=> ($b->[2] || 0)

or you be super sneaky and do

  map { [ $_, "${_}0" =~ /^([a-z-]+)(\d+)/i ] }

The appended 0 assures that a digit will be matched, but won't end up
affecting the actual order of numeric comparisons.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to