explanation needed

Discussion in 'Perl Misc' started by anirban, Jan 20, 2007.

  1. anirban

    anirban Guest

    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, Jan 20, 2007
    #1
    1. Advertising

  2. anirban

    anirban Guest

    Thanks a lot Michele.Your explanation helped me a lot.
    anirban
    anirban, Jan 22, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VK
    Replies:
    1
    Views:
    421
    Richard Tobin
    May 18, 2006
  2. Replies:
    9
    Views:
    354
    Christian Bau
    Feb 16, 2006
  3. NoNeYa
    Replies:
    42
    Views:
    1,155
    John W. Kennedy
    Aug 22, 2007
  4. korean_dave
    Replies:
    0
    Views:
    364
    korean_dave
    May 19, 2008
  5. korean_dave

    Dummy explanation to win32com needed

    korean_dave, Oct 22, 2008, in forum: Python
    Replies:
    2
    Views:
    295
    Tim Golden
    Oct 23, 2008
Loading...

Share This Page