"lyoute" <> wrote in message
news:...
> i got a set of files all looks like: (with fixed dimension 8x
[snip]
> actually i got this done while i still storing the pattern in a
> @pattern[8][8].
> just doubt if i still can rotate it after the pattern was written into a
> file....
I guess the matrix approach is the most flexible thing, you can rotate,
mirror, flip things just playing with the indices. Comment/uncomment lines
at your ease and compare the results.
I illustrated it step-by-step but one might want to code it more
efficiently. Works for any NxN matrix.
HTH,
Zoltan
use strict;
use warnings;
my ($line,@arr);
my $ctr = 0;
while (my $line = <DATA>) {
chomp($line);
$arr[$ctr++] = $line; }
# no transformation
foreach my $xc (0..$#arr) {
foreach my $yc (0..$#arr) {
# print substr($arr[$xc],$yc,1); # no transformation
print substr($arr[$yc],$xc,1); # rotate 90 degrees
# print substr($arr[$xc],$#arr-$yc,1); # flip horizontally
# print substr($arr[$#arr-$xc],$yc,1); # flip vertically, etc
}
print "\n";
}
__DATA__
..X..XO..
X...XO..
OXX.XO..
OOOXXO..
....OO.O.
...O.....
.........
.........