Here is a quick late-night attempt.... It assumes the words only
consist of [A-Za-z] and relatively small integers. Not perfect, but
it does work on your sample dataset. Oh, it also sorts 'aa' before 'a1' which is probably not correct, but you didn't
mention it in the requirements.
#!/usr/bin/perl -wT
use strict;
{ # Create an interleaved 'AaBbCc' mapping
my %map;
$map{$_} = 2*(ord($_)-ord('A')) for 'A'..'Z';
$map{$_} = 2*(ord($_)-ord('a'))+1 for 'a'..'z';
# use interleaved map to munge word into a string that will sort "co
+rrectly"
sub dictize {
my $word = shift;
$word =~ s/(\d+|[A-Za-z])/chr($map{$1}||60+$1)/ge;
return $word;
}
}
my @words = qw(bigBoy bigbang bigboy
x10y x9y x11y);
# Sort based on lowercased munged words,
# use the non-lowercased version as a tiebreaker
my @sorted = map {$_->[0]}
sort {$a->[1] cmp $b->[1] or
$a->[2] cmp $b->[2]}
map {[$_,dictize(lc),dictize($_)]}
@words;
print "$_\n" for @sorted;
__END__
bigbang
bigBoy
bigboy
x9y
x10y
x11y
-Blake
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.