bluray has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to get the transpose of a .csv file. When I executed the code below, I get the error message "Can't use a string (" ") as an ARRAY ref while "strict refs" in use at line 17". I am not sure how to solve this problem.
#!/usr/bin/perl -w use strict; use warnings; use Text::CSV_XS; open(my $FILE1, '<', "inputfile.csv") or die "cannot open file1 $!\n"; open(my $FILE2, '>', "outputfile.csv") or die "cannot open file2 $!\n" +; my $csv =Text::CSV_XS-> new({binary=> 1, eol=> $/, sep_char=> "\t", al +ways_quote=>1}); my @tfields; while(my $row=$csv->getline($FILE1)) { my @fields=@$row; for my $y (0..(@fields-1)) { for my $x (0..@{$fields[$y]}-1) { $tfields[$x][$y] = $fields[$y][$x]; $csv->print($FILE2,\@tfields); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Transpose of an array
by ikegami (Patriarch) on Oct 13, 2011 at 19:17 UTC | |
by bluray (Sexton) on Oct 13, 2011 at 20:07 UTC | |
by ikegami (Patriarch) on Oct 13, 2011 at 20:27 UTC | |
|
Re: Transpose of an array
by Eliya (Vicar) on Oct 13, 2011 at 19:13 UTC |