title: Transposing an array of elements
body: <p>I am trying to transpose an array. </p>
  
  <p>I tried the following code...</p>
  
  <pre><code>#! /usr/bin/perl
  
  use strict;
  use warnings;
  use autodie;
  
  open my $fh, '&lt;',"op.txt" || die "$!";
  open my $wh , '&gt;',"pwl.txt" || die "$!"; 
  select ($wh);
  while (my $line = &lt;$fh&gt;) { 
    my @rows = $line;
    my @transposed;
    for my $row (@rows) {
      for my $column (0 .. $#{$row}) {
        push(@{$transposed[$column]}, $row-&gt;[$column]);
      }
    }
    for my $new_row (@transposed) {
      for my $new_col (@{$new_row}) {
        print $new_col, " ";
      }
      print "\n"; 
    }
  }
  </code></pre>
  
  <p>**********INPUT FILE******</p>
  
  <pre><code>1 2 3
  4 5 6
  7 8 9
  </code></pre>
  
  <p>********** EXPECTED OUTPUT FILE *******</p>
  
  <pre><code>1 4 7
  2 5 8
  3 6 9
  </code></pre>
  
  <p>******** GENERATED OUTPUT FILE *******</p>
  
  <p>Currently couldn't able print anything. script shows the error
  "can't use string ("1 4 7") as an array ref while "strict refs" in use</p>
  
  <p>Reference:
  used the following reference...
  <a href="https://stackoverflow.com/questions/3249508/transpose-in-perl">Transpose in perl</a>
  however in this reference example, array input lines are declared manually where as i am trying to process a array which is in a text file</p>
  
  <p>could anybody help me where i did mistake?</p>
  
  <p>Many Thanks</p>