467,108 Members | 1,282 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,108 developers. It's quick & easy.

How to assign data after getting from CSV?

I faced a problem using Perl. I get the data from CSV using
Expand|Select|Wrap|Line Numbers
  1. $csv = "test.csv";
  2. open(DAT, $csv) || die("Cannot Open File");
  3.  
  4. while (<DAT>) {
  5.  
  6.     my @new  = ();
  7.  
  8.     push(@new, $+) while $_ =~ m{
  9.         "([^\"\\]*(?:\\.[^\"\\]*)*)",?
  10.  
  11.            |  ([^,]+),?
  12.  
  13.            | ,
  14.         }gx;
  15.  
  16.        push(@new, undef) if substr($_, -1,1) eq ',';
  17.        print "$_\n" for @new;
  18. }
  19.  
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.
Aug 1 '08 #1
  • viewed: 908
Share:
4 Replies
KevinADC
Expert 2GB
I don't understand your question.
Aug 1 '08 #2
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?
Aug 1 '08 #3
KevinADC
Expert 2GB
this is the assignment operator: "="

$this = 'that';
Aug 1 '08 #4
Can you expalin your problem in more details if this problem still exists.
Aug 6 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by gaffar | last post: by
2 posts views Thread by Jim McGivney | last post: by
11 posts views Thread by skumar434@gmail.com | last post: by
5 posts views Thread by * Tong * | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.