Transpose tab deliminated textfile with perl using Array::Transpose -


i have several huge textfiles need transpose. stuck on idea using array::transpose purpose - somehow can't come end... here source code:

#!/usr/bin/perl  use warnings; use strict; use array::transpose;  $eachline; $input=$argv[0]; @array;  open (in, "<$input") or die ("no such file!"); while(defined($eachline=<in>)) {    push @array, split(/\t/,$eachline); }  @array2=transpose(\@array); 

i can not see, wrong idea, documentations says:

use array::transpose; @array=transpose(\@array); 

the error code says:

can't use string ("") array ref while "strict refs" in use @ /usr/local/share/perl/5.14.2/array/transpose.pm line 91, <in> line 3. 

i new in programming, in perl. don't understand error means. happy helpful answer!

cheers, newbie!

edit: have forgotten say: input file says:

parameter1 \t parameter2 \t .... parameterxy \n  value1 \t value2...  

and on.

i want output file says:

parameter1 \t value1 \t .....valuexy \n parameter2 \t value2 \t...... 

you need push each row separately.

    @row = split(/\t/,$eachline);     push @array, \@row; 

@row 1-d array. pushing \@row makes 2-d array. think want chomp remove line endings.

full program

    #!/usr/bin/perl      use warnings;     use strict;     use array::transpose;     use data::dumper;      $eachline;     $input=$argv[0];     @array;      open (in, "<$input") or die ("no such file!");     while(defined($eachline=<in>))     {        chomp $eachline ;        @row = split(/\t/,$eachline);        push @array, \@row;     }      print dumper(\@array) ;     @array2=transpose(\@array);      print dumper(\@array2) ; 

another way push @array, [ split(/\t/,$eachline) ] ; - [ ] creates array reference.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -