Re: open a ascii file and rotate the content 90 deg...

From: kz (notpublic_at_restricted.com)
Date: 02/02/04

  • Next message: Xaver Biton: "Re: network card"
    Date: Mon, 2 Feb 2004 15:01:38 +0100
    
    

    "lyoute" <lyoute@softhome.net> wrote in message
    news:401dd3de_3@rain.i-cable.com...
    > i got a set of files all looks like: (with fixed dimension 8x8)
    [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.....
    ........
    ........


  • Next message: Xaver Biton: "Re: network card"

    Relevant Pages