explanation needed

A

anirban

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top