Getting columns from csv file in perl

Discussion in 'Programming/Scripts' started by pnsreee, Apr 24, 2007.

  1. pnsreee

    pnsreee New Member

    Hi All,

    How can i get columns from cvs file into an array with out using Text::xSV or Text::CSV_XS.
    The CSV file is a dynamic file.

    the fields are like this

    Numb,Name,Class,Type,......

    201,Bazaar,b2,53,..........

    121,Raymond,y1,02,...

    232,Robert,p1,04,...............




    I am using following code to get columns.

    @tmp = `more +2 flat1.txt | cut -d "," -f $i` ;

    It is giving out put and also error saying that refer help.
    Can any one give me equivalent to this
     
  2. ghostdog74

    ghostdog74 New Member

    you are using perl, and then you are using other OS tools like more and cut. this is overkill. in perl , you can split your string eg perldoc -f split, you can see how its done. if you want to use shell tools, awk can do that.
     
    Last edited: Apr 24, 2007

Share This Page