That's my try, and it seems to work perfectly with the given example, and some of my own tries.my @sorted = map $_->[0], sort { my $i = 0; { my $A = $a->[1][$i]; my $B = $b->[1][$i]; defined($A) || defined($B) # Stop if both undef and ( defined($A) <=> defined($B) # Defined wins over undef or ( $A !~ /\d/ || $B !~ /\d/ # $A or $B is non-integer ? (lc $A cmp lc $B) # ?? Stringy lowercase || ( $A cmp $B) # -> Tie breaker : $A <=> $B # :: $A and $B are intege +rs ) or ++$i && redo # tie => next part ); } } map [ $_, [ split /(\d+)/ ] ], @unsorted;
@sortedqw( bigbang x10y x9y bigboy bigBoy x11y )
Update - integer-detection altered per argarthin's reply.qw( bigbang bigBoy bigboy x9y x10y x11y )
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
In reply to Re: Dictionary-style sort a la Tcl?
by Juerd
in thread Dictionary-style sort a la Tcl?
by argathin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |