"Use a nested hash", I thought. It's one of those thoughts that sounds like it offers a neater solution than it does. This does the job, but it's a little contrived. Having said that, once you've got the stuff into the data structure you may find there are lots of other great things you can do with it, so there may be some merit here that I haven't spotted. See how you like:
my %sort; for (<DATA>) { m!(\d+)(\D+)(\d+)(\D*)R(\d+)B?(\d*)\.(\w+)$!; $sort{$7}{$6}{"$1$2"}{$3}{$5}{$4} = $_; } for my $first (sort keys %sort) { for my $second (reverse keys %{$sort{$first}}) { for my $third (sort keys %{$sort{$first}{$second}}) { for my $fourth (sort keys %{$sort{$first}{$second}{$third} +}) { for my $fifth (sort keys %{$sort{$first}{$second}{$thi +rd}{$fourth}}) { for my $sixth (sort keys %{$sort{$first}{$second}{ +$third}{$fourth}{$fifth}}) { print $sort{$first}{$second}{$third}{$fourth}{ +$fifth}{$sixth}; } } } } } }
This prints out
18AD13XR0B3.ras 18DD13AR0B2.ras 5A344R2B15.ras 13B29AR0B1.ras 113A22R1.ras 113A29R0.ras 113A29AR0.ras 113B28R2.ras 5A32R0.ras 5A33R0.ras 5A34R0.ras 5A35R0.ras 5A35SR0.ras 18AD13XR0B3.vec 18DD12YR0B2.vec 18DD13AR0B2.vec 5A344R2B15.vec 113B29AR0B1.vec 113A22R1.vec 113A28R0.vec 113A28AR0.vec 113A28R1.vec 113A28R2.vec 113A28AR2.vec 113A29R1.vec 113A29AR2.vec 5A32R0.vec 5A33R0.vec 5A34R0.vec 5A35R0.vec
... if that's not exactly what you wanted, you can probably tweak the code. And maybe some greater monk than I can make the recursive unpacking of the hash a bit shorter.

Merry Christmas!

§ George Sherston

In reply to Re: complex sort by George_Sherston
in thread complex sort by mkmcconn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.