Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi,

I could use some guidance on the best way to tackle a somewhat complex sorting problem I need to work though. I will try to keep this as generic as possible.

I have to grab 4 numbers from every line in a file. Each line is formatted in a very predictable pattern. Say I name each number like so:-

$row_lx
$row_ly
$row_ux
$row_uy

NOTE: Many of the $row_lx values will be the same.
NOTE: MOST of the $row_ly values will be different.

Here is a nice, neat, golden output. Imagine all of the following lines were originally completely out of order:-

((1.0 0.1) (99.0 0.2))
((1.0 0.2) (99.0 0.3))
((1.0 0.3) (99.0 0.4))
((5.0 0.4) (48.0 0.5))
((48.1 0.4) (99.0 0.5))
((1.0 0.5) (99.0 0.6))
((1.0 0.6) (13.0 0.7))
((13.1 0.6) (99.0 0.7))

Notice that the second number (highest priority), $row_ly, always increases, and sometimes it is repeated. When it does repeat, always print the $row_lx numbers in order (second priority).

I hope this is clear enough. Any recommendations? I think I need a hash with two primary key values, but I don't know how to sort the hash to produce the above output.

Thanks,
-Anonymous Monk #N


In reply to Sorting large sets of geometric coordinates by Anonymous Monk

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 pondering the Monastery: (2)
As of 2024-04-19 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found