in reply to Re^4: Sorting multi-dimensional arrays
in thread Sorting multi-dimensional arrays

It's quite possible that CC100A _does_ go after CC1000, in his system...
That would be what I call an accidental feature.. :-) Better to be safe than sorry, remember? The substr solution will work regardless of circumstances and won't surprisingly blow up if he moves the script to a system with different alphanumeric order. I am in no way dismissing cmp off hand as it is indeed a candidate if you are absolutely certain about your data format. But that's just what I find to be a dangerous assumption. I mean, who needs four digit years, right? :-) See also my signature..

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^5: Sorting multi-dimensional arrays
by sauoq (Abbot) on Sep 11, 2002 at 19:17 UTC
    The substr solution will work regardless of circumstances. . .

    What about with CCI001 and CDI001? I think RMGir is right: the sort order is underspecified. Even something like:

    # Simplified for illustration. Will not work for OP. Would benefit fro +m ST. sort { my ($a1,$a2) = $a =~ /([A-Z]*)(\d*)/; my ($b1,$b2) = $b =~ /([A-Z]*)(\d*)/; $a1 cmp $b1 || $a2 <=> $b2 } @list;
    is likely to break with CC100A and CC100B. Given the elements that he gave us I'd think that a variation on the above would work but that guess isn't any better than yours or anyone's.

    -sauoq
    "My two cents aren't worth a dime.";
    
      Note that yours is making even fewer assumptions than mine, which makes fewer assumptions than cmp. Mine might be making too many assumptions - we can't tell. Your solution is better. The cmp on the other hand is very likely to be making too many assumptions. And that's what I was arguing - to make fewer assumptions.

      Makeshifts last the longest.