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

Please help me understand this code...

P: 13
I am new to Perl and I have these codes but I am not quite understand the regular expression here. Can any1 please explain to me?

Expand|Select|Wrap|Line Numbers
  1. $csv = "test.csv";
  2. open(DAT, $csv) || die("Cannot Open File");
  3.  
  4. while (<DAT>) {
  5.     my @new  = ();
  6.  
  7.     push(@new, $+) while $_ =~ m{          #what does these means
  8.         "([^\"\\]*(?:\\.[^\"\\]*)*)",?
  9.            |  ([^,]+),?
  10.            | ,
  11.         }gx;
  12.  
  13.     push(@new, undef) if substr($_, -1,1) eq ',';
  14.  
  15.     my $string = format_string(@new);
  16.     my $query = qq{Insert into person_info VALUES ($string)};
  17.     print $query, "\n"; 
  18. }  
  19.  
  20.  sub format_string {  
  21.         my $string; 
  22.         foreach (@_) {
  23.             if  (/[^\d]/) {          #what does these mean
  24.                 $string .= qq{"$_",};
  25.             } else {
  26.                 $string .= qq{$_,};
  27.             }
  28.         }
  29.         return substr($string, 0, -1); 
  30.     }
Aug 11 '08 #1
Share this Question
Share on Google+
1 Reply


KevinADC
Expert 2.5K+
P: 4,059
See your thread on Devshed.
Aug 11 '08 #2

Post your reply

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