in reply to Extraction of List of Coordinates

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