in reply to Re^2: [ Natural Sort ]: Sorting a string with numbers
in thread [ Natural Sort ]: Sorting a string with numbers
#!/usr/bin/perl -w use strict; my @h = ( qw( psapp1 psapp psapp2 psepapp1 psepapp psepapp2 psimgprod pspappuat pswebapp2 pswebapp ) ); my @h_sorted = @h[ map { unpack "N", substr($_,-4) } sort map { my $key = $h[$_]; $key =~ s[(\d+)][ pack "N", $1 ]ge; $key . pack "N", $_ } 0..$#h ]; foreach (@h_sorted) { print "$_\n"; };
The "psapp" items sort properly, but the "psepapp" and "pswebapp" ones show the problem I'm asking about. Thanks! -s-psapp psapp1 psapp2 psepapp1 psepapp2 psepapp psimgprod pspappuat pswebapp2 pswebapp
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: [ Natural Sort ]: Sorting a string with numbers (fix)
by tye (Sage) on Sep 18, 2005 at 03:25 UTC | |
by blueflashlight (Pilgrim) on Sep 18, 2005 at 17:41 UTC |