Here is an OO-way (perhaps more readable):
#!/usr/bin/perl use strict; use warnings; #===================================================================== +===== {package point; sub new {return bless {x=>$_[1], y=>$_[2]}, __PACKAGE__;} sub Print { my ($self) = @_; return "(" . $self->{x} . "," . $self->{y} . ")"; } 1; } #===================================================================== +===== {package rect; sub new { # Takes 2 'point's return bless {p1=>$_[1], p2=>$_[2]}, __PACKAGE__; } 1; } #===================================================================== +===== my @rect_x = (3,2,4,0,3,0,4,0,3,2,0,4); my @rect_y = (0,0,0,1,1,0,3,3,3,3,2,2); my @rectangles; # Create the 'rect' objects, and collect in @rectangles for my $idx(0..$#rect_x){ push @rectangles, rect::->new(point::->new($rect_x[$idx], $rect_y[$i +dx]), undef); } @rectangles = sort { $b->{p1}{x} <=> $a->{p1}{x} || $a->{p1}{y} <=> $b->{p1}{y} } @rectangles; for (0..$#rectangles){ my $r = $rectangles[$_]; print "Rectangle ", ($_+1) , " -> ", $r->{p1}->Print(), "\n"; }

        ...it is unhealthy to remain near things that are in the process of blowing up.     man page for WARP, by Larry Wall


In reply to Re: Sorting geometric coordinates based on priority by NetWallah
in thread Sorting geometric coordinates based on priority by Ppeoc

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.