By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,933 Members | 1,675 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,933 IT Pros & Developers. It's quick & easy.

How to assign data after getting from CSV?

P: 13
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
Share this Question
Share on Google+
4 Replies


KevinADC
Expert 2.5K+
P: 4,059
I don't understand your question.
Aug 1 '08 #2

P: 13
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 2.5K+
P: 4,059
this is the assignment operator: "="

$this = 'that';
Aug 1 '08 #4

P: 7
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.