If your data is tab separated you should split on a \t.
If you want your sum loop to count the number of elements in a row a better way would be
for ( @$row ) { $sum++; }
If you want to print ';' separated you can just use a join. Although if you want this as input to some other program it may be safer to look at something like Text::CSV and set semicolon as the sep_char
print join( '; ', @$row );
Couple of best practice notes; use warnings is preferred over -w and use 3 argument open.
Putting it all together, not sure it is exactly what you want but should help get you there.
#!/usr/bin/perl use strict; use warnings; open my $fh, '<', "/tmp/Gene.txt" or die $!; my @content = (<$fh>); close($fh); my @myArray; for my $row (@content) { my @columns = split '\t', $row; push @myArray, \@columns; } my $title_row = shift @myArray; for my $row (@myArray) { my $sum = 0; for ( @$row ) { $sum++; } print "$row->[0] is $sum\n"; print join( '; ', @$row ); }
In reply to Re: storing a file in 2d array
by rnewsham
in thread storing a file in 2d array
by shabird
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |