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).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 ... }
And the output:#!/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
Cheers,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
Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder
In reply to Re: Extraction of List of Coordinates
by tmoertel
in thread Extraction of List of Coordinates
by EchoAngel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |