$myPolygons =
"
A
-1.1,2,0 -3.1,4,0 -5.1,6,0 -7.1,8,0 1,2,0
C
9,-8.1,0 7,-6.1,0 5,-4.1,0 3,-2.1,0 9,-8.1,0
";
while ($myFile =~ m{(.*?)}gs)
{
$tag = $1;
if ($tag =~ m{(.*?)}gs)
{
$name = $1;
if ($tag =~ m{(.*)}g)
{
$points = $1;
while ($points =~ m{\G(-?\d*\.?\d*),0*\s*}gs)
{
push @{$points_by_name{$name}}, $1;
}
}
}
}
####
@_ = ($x0, $y0, $x1, $y1, $x2, $y2, $x3, $y3)
####
$x0, $y0, $x1, $y1
####
@{$points_by_name{$key}}[0..3];
@{$points_by_name{$key}}[2..5];
@{$points_by_name{$key}}[4..7];
@{$points_by_name{$key}}[6..9];
####
foreach my $key (keys %points_by_name)
{
foreach (@{$points_by_name{$key}}
{
for (my $i=0; $i<=$#{$points_by_name{$key}} $i+=2)
{
sub(@{$points_by_name{$key}}[$i..$i+3], $x2, $y2, $x3, $y3)
}
}
}
####
foreach my $key (keys %other_hash)
{
foreach (@{$other_hash{$key}}
{
for (my $i=0; $i<=$#{$points_by_name{$key}} $i+=2)
{
my @temp = @{$other_hash{$key}}[$i..$i+3]
foreach (@temp)
{
sub($x0, $y0, $x1, $y1, @temp)
}
}
}
}