Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > explanation needed

Reply
Thread Tools

explanation needed

 
 
anirban
Guest
Posts: n/a
 
      01-20-2007
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

 
Reply With Quote
 
 
 
 
anirban
Guest
Posts: n/a
 
      01-22-2007
Thanks a lot Michele.Your explanation helped me a lot.
anirban

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explanation needed of binary operators NoNeYa Java 42 08-22-2007 09:03 PM
CONCEPT OF DAO IN J2EE --- EXPLANATION NEEDED soody Java 2 06-05-2007 08:35 AM
standalone in prolog: specs explanation needed VK XML 1 05-18-2006 10:43 PM
explanation needed on const pointers deepunayak@gmail.com C Programming 9 02-16-2006 10:31 PM
explanation needed for optical illusion in digital photo Eigenvector Digital Photography 27 08-02-2003 05:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57