Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
"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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-26 07:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found