467,114 Members | 1,320 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

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

Please help me understand this code...

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
  • viewed: 914
Share:
1 Reply
KevinADC
Expert 2GB
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.

Similar topics

6 posts views Thread by Buck Rogers | last post: by
23 posts views Thread by Jason | last post: by
7 posts views Thread by Mickyd1561@aol.com | last post: by
7 posts views Thread by garyusenet@myway.com | last post: by
2 posts views Thread by almurph@altavista.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.