Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   explanation needed (http://www.velocityreviews.com/forums/t901518-explanation-needed.html)

anirban 01-20-2007 08:38 AM

explanation needed
 
dear all
i am a beginner in perl.i am familiar with regex.but somewhere in the
net i hv found the following example which i cdnt understand.and there
was no explanation given in it.it would be very much helpful for me if
anyone kindly explain the following snippet of code.i understood what
it is actually doing.its jst retrieving the comma separated values frm
$text one by one.but i cdnt understand the regex part inside the while
loop inside the parse_csv subroutine.

$text = q<XYZZY,"","O'Reilly, Inc","Wall, Larry","a \"glug\"
bit,",5,"Error, Core Dumped">;
@new=&parse_csv($text);
foreach(@new){
print "$_\n";
}

sub parse_csv {
my $text = shift; # record containing comma-separated values
my @new = ();
push(@new, $+) while $text =~ m{
"([^\"\\]*(?:\\.[^\"\\]*)*)",?
| ([^,]+),?
| ,
}gx;
push(@new, undef) if substr($text, -1,1) eq ',';
return @new; # list of values that were comma-separated
}
thanking you in advance

anirban


anirban 01-22-2007 09:23 AM

Re: explanation needed
 
Thanks a lot Michele.Your explanation helped me a lot.
anirban



All times are GMT. The time now is 07:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.