How to assign data after getting from CSV?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NOTSomebody
    New Member
    • Jul 2008
    • 13

    How to assign data after getting from CSV?

    I faced a problem using Perl. I get the data from CSV using
    Code:
    $csv = "test.csv";
    open(DAT, $csv) || die("Cannot Open File");
    
    while (<DAT>) {
    
        my @new  = ();
    
        push(@new, $+) while $_ =~ m{
            "([^\"\\]*(?:\\.[^\"\\]*)*)",?
    
               |  ([^,]+),?
    
               | ,
    		}gx;
    
           push(@new, undef) if substr($_, -1,1) eq ',';
           print "$_\n" for @new;
    }
    my test data in excel(convert to csv) is:
    a,a123,abc
    b,b123,bcd
    c,c123,cde

    then my result shown is

    a
    a123
    abc

    b
    b123
    bcd

    c
    c123
    cde


    What I am wondering is that how can I assign the result "a"-->Name, "a123"-->contact_no, "abc"-->address. Same for b and c.
    Last edited by numberwhun; Aug 1 '08, 12:28 PM. Reason: Please use code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    I don't understand your question.

    Comment

    • NOTSomebody
      New Member
      • Jul 2008
      • 13

      #3
      I mean, from i tried your solution for me for the previous post. And now I am able to retrieve the fields. Now, i want to extract 1 field from the csv and assign the data to say $name, $contact_no, $address. How do I assign?

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        this is the assignment operator: "="

        $this = 'that';

        Comment

        • Ritusriv
          New Member
          • Jul 2008
          • 7

          #5
          Can you expalin your problem in more details if this problem still exists.

          Comment

          Working...