Velocity Reviews

Velocity Reviews (
-   Perl Misc (
-   -   explanation needed (

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 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">;
print "$_\n";

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


anirban 01-22-2007 09:23 AM

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

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.