Oh, I've done exactly this recently, here's the sub for sorting cloth sizes:
my @sizes = qw/6XS 5XS 6XL L S xL m 3xs/;
my $sort_sizes_sub = sub {
my $uc_a = uc($a);
my $uc_b = uc($b);
my @sizes_sorted = qw/6XS 5XS 4XS 3XS 2XS XS S M L XL XXL 2XL 3XL 4X
+L 5XL 6XL/;
return 0 if $uc_a eq $uc_b;
foreach my $s (@sizes_sorted) {
if ($s eq $uc_a) {
return -1;
}
if ($s eq $uc_b) {
return 1;
}
}
};
print join(' ', @sizes). "\n";
print join(' ', sort $sort_sizes_sub @sizes). "\n";
Result:
6XS 5XS 6XL L S xL m 3xs
6XS 5XS 3xs S m L xL 6XL
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|