Background: Window Excel supports maximum 256 columns or 64K rows. Many of our CSV files were generated with 30~60 rows and 1000~2500 columns. So it can't be fed to excel directly.

I would like to invert row and columns as following:

#!/usr/bin/perl my @data; while (<DATA>) { chomp; push @data,[split /,/]; } for my $z ( 0 .. $#data ) { for my $v ( 0 .. $#{$data[$z]} ) { print "$data[$v][$z],"; } print "\n"; } __DATA__ Date,a,b,c,d,e,f Mon-1,11,12,13,14,15,16 Mon-2,21,22,23,24,25,26 Tue-1,31,,33,34,35,36 Tue-2,41,42,,44,45,46 Wed-1,51,52,53,54,55,56 Wed-2,61,62,63,64,65,66

Everything appears working fine

When I run it against the csv file, it can't convert all columns to row. I am puzzled by the behavior. It may be related to the csv content. Here is a small portion of one csv file

===

,/dir/dir1/file1,/dir/dir1/dir3,/dir/dir1/file2,/dir/dir1/file3,/dir/dir1/dir2,.....(up to 1000-2000 diretory or filename)

May-1,34,44,44,443,68,93,,,,,993,9,2,,,,13343,...(up to 1000-2000 columns)

May-2,343,343,,343,343,,,,4343,5,56,,,,,,........

May-3,3030...

....

May-30....

===

I like to see output like:

May-1,May-2,May-3,May-.......,May-30 /dir/dir1/file1,3,34,,,,34,....... /dir/dir1/dir3,..... /dir/dir1/file2,.... /dir/dir1/file3,... /dir/dir1/dir2.... ..up to 1000-2000 rows..
Thanks for your comments,

carl


In reply to Invert CSV by roadtest

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.