Hi, I have this front end CSS data stored in a web page. Here is the data in csv file.

secid,Initial_shares 002826,3777 0028262,3777 0028262,3777 0028262,3777 0028262,3777 0028262,3777
I need to convert this text file into the below format. once, i convert it to below format, i will be able to display it on the front end. this format below is used to display data in jqgrid.
var secid = [ "002826", "0028262", "0028262", "0028262", "0028262", +"0028262"]; var Initial_shares = [ "3777", "3777", "3777", "3777", "3777", "3777"1 ];
In order to convert the text to above format, i have used the below perl code. Please note. This conversion is static. i.e. it knows how many columns are there. In this case, there will be 2 columns. secid and Initial_shares. so here is the static code.
my @a=(); my @b=(); my @a1=(); my @b1=(); my @perl_array=(); my @filena = split(/\|/, $filename); open (TXT, "<$filename") || die "Can't open $filename: $!\n"; while (my $line=<TXT>) { chomp($line); ($a2, $b2) = split /,/, $line; push @a,('"',"$a2",'"',','); push @b,('"',"$b2",'"',','); } splice @a,0,4; #this splice is used to remove the header name. i.e. +first row data- secid, Initial_shares splice @b,0,4; push @a1,"var secid=[@a]"; push @b1,"var Initial_shares=[@b]"; push @perl_array, "@a1; @b1"; close TXT;
The @perl_array will be then exactly similar to the kind of data we were expecting at the start. i wil transfer this perl variable to front end for displaying then. I need help in the following case. What if instead of 2 columns, there are 5 columns. How can we convert the same csv file to the format mentioned earlier. it should be all dynamic. Can someone shed some light please.

In reply to Get CSV data and convert it to other format data dynamically. by ash1351

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.