in reply to matching quotes
open(FILE, "test.txt") || die; { local $/ = undef; #set to 'slurp' mode $file = <FILE>; #read entire file into $file } close FILE; $start = '"'; $end = '"'; my $inside = 0; my $oldpos = 0; while ($file =~ /(?<!\\)(\Q$start\E|\Q$end\E)/g) { if ($inside == 0) { $oldpos = pos($file) - length($start); $inside++; } else { print substr($file, $oldpos, pos($file)-$oldpos); $inside--; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: Re: matching quotes
by Anonymous Monk on May 24, 2000 at 00:19 UTC | |
by takshaka (Friar) on May 24, 2000 at 00:41 UTC | |
by perlmonkey (Hermit) on May 24, 2000 at 00:26 UTC |