Oops, I found an error my parser. Here's version 1.0.2:

DATA_LOOP:
while( my $line = <DATA> ){
  print $line;

  my @captured = ( '' );
  my $inside = 0;

CAPTURE_LOOP:
  while( 1 ){

    if( $line =~ m{ \G ( [^"\\]+ | \\ ["\\] ) }gcx ){
      $captured[-1] .= $1 if $inside;
    }elsif( $line =~ m{ \G \" }gcx ){
      $inside ^= 1;
      push @captured, '' if ! $inside;
    }else{
      last CAPTURE_LOOP;
    }

  }

  if( $inside ){
    warn "missing closing quotes\n";
  }else{
    pop @captured; # last item is a bogus empty string
  }

  print "\t$_\n" for @captured;
  print "\n";
}

__DATA__
"something" 444
\"escaped quote\" 321
"\"esc quote\" other stuff" 567
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; . NET
CLR 1.1.4322; msn OptimizedIE8;ESMX)" 556 "\"Mozilla\"" 555



-- 
Just my 0.00000002 million dollars worth,
        Shawn

Programming is as much about organization and communication
as it is about coding.

Why fit in when you can stand out?
        Dr. Seuss

The only way that problems get solved in real life is with a lot of
hard work on getting the details right.
        Linus Torvalds

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to