While the other solutions offered work on a file that is already entirely slurped into memory, it is possible to combine the flip flop operator (".." in scalar context) with line oriented file processing. You could try something like:
my ( @revision_array, @current_revision); while (<DATA>) { my $status; if ( $status = /<!-- Start_of_revision-->/ .. /<!-- End_of_revision- +->/ and $status != 1 and $status !~ /E/ ) { push @current_revision, $_; } if ( $status =~ /E/ ) { push @revision_array, join '', @current_revision; undef @current_revision; } } my $count; for my $revision (@revision_array) { print 'revision ', ++$count, ": \n$revision\n"; } __DATA__ <head>somthing</head> <!-- Start_of_revision--> some revised text <!-- End_of_revision--> some other regular tags and stuff <br> <!-- Start_of_revision--> another revision <!-- End_of_revision--> the rest of the document
That obscure line about testing $status to see if it contains the letter 'E' is to detect the state change from "inside the matching area" to "outside the matching area".
For more information, see 'perldoc perlop'. Search for "Range Operators", and pay attention to the paragraphs about scalar context. If you are crazy, and enjoy using OO beyond its range of usefulness, then you might like Bit::FlipFlop.
-Colin.
WHITEPAGES.COM | INC
In reply to Re: pattern matching
by cmeyer
in thread pattern matching
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |