It seems that you're on the right track. You just need to extract the left, right, top, and bottom coordinates from the corner points of each rectangle specification. This is easy to do using min and max from List::Util:
sub minmax { ( min(@_), max(@_) ) } # helper function for (@list_of_Num_Extraction) { if (/^(\d+),(\d+):(\d+),(\d+)$/) { my ($l,$r, $t,$b) = (minmax($1,$3), minmax($2,$4)); for my $x ($l .. $r) { # left to right for my $y ($t .. $b) { # top to bottom $Unique_Num_List{($x-1)*$num_columns + $y} = "($x,$y)"; } } } # and so on ... }
Just to show that it works, here's a bit of code that uses the above method to draw rectangles onto a virtual screen (represented by a sparse array).
#!/usr/bin/perl -w use strict; use List::Util qw( min max ); sub minmax { ( min(@_), max(@_) ) } # draw rectangles onto sparse screen matrix my %screen; # sparse screen matrix my $rectangle_name = "A"; for (<DATA>) { if (/^(\d+),(\d+):(\d+),(\d+)$/) { my ($l,$r, $t,$b) = (minmax($1,$3), minmax($2,$4)); for my $x ($l .. $r) { # left to right for my $y ($t .. $b) { # top to bottom $screen{$y}{$x} = $rectangle_name; } } } $rectangle_name++; } # print out screen for my $f (sub {$_/10 % 10}, sub {$_ % 10}, sub {"_"}) { print " ", (map &$f, 1..20), "\n"; } my ($ymin, $ymax) = minmax(keys %screen); for my $y ($ymin .. $ymax) { printf "%2d|", $y; for my $x (1 .. 60) { print $screen{$y}{$x} || " "; } print "\n"; } __DATA__ 2,2:4,4 5,10:10,5 12,5:6,1 8,12:1,15
And the output:
00000000011111111112 12345678901234567890 ____________________ 1| CCCCCCC 2| AAA CCCCCCC 3| AAA CCCCCCC 4| AAA CCCCCCC 5| BCCCCCCC 6| BBBBBB 7| BBBBBB 8| BBBBBB 9| BBBBBB 10| BBBBBB 11| 12|DDDDDDDD 13|DDDDDDDD 14|DDDDDDDD 15|DDDDDDDD
Cheers,
Tom

In reply to Re: Extraction of List of Coordinates by tmoertel
in thread Extraction of List of Coordinates by EchoAngel

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.