I have a flat array of coordinates and I want to iterate and extract pairs of x and y coordinates. The same logic could apply to triples for RGB colors. This is what I have so far, but it doesn't feel super flexible or elegant.
my @coords = qw(1 5 2 6 3 8 6 12 7 5);
for (my $i = 0; $i < @coords; $i += 2) {
my $x = $coords[$i];
my $y = $coords[$i+1];
print "$x, $y\n";
}
There has to be a better way to do this right?