Jan Eden <mailto:[EMAIL PROTECTED]> wrote:
: Hi,
: 
: I use the following regex to split a (really simple) file into
: sections headed by <h1>.+?</h1>:
: 
: while ($content =~ m#<h1>(.+?)</h1>(.+?)(?=<h1>)#gs) {
:     ...
: }

     The answer may be in your description. Use 'split'. When you
use a capture inside the regular expression in 'split', the
capture is returned. @content is 'shift'ed to rid the first empty
element (or filled if there is something before the first <h1>)
returned by split.


#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper 'Dumper';

my $content = do{ local $/ = undef; <DATA>; };

my @content = split m|<h1>(.+?)</h1>|, $content;
shift @content;

print Dumper [EMAIL PROTECTED];

__END__
<h1>heading 1</h1>
Some stuff
<h1>heading 2</h1>
Some stuff
<h1>heading 3</h1>
Some stuff
<h1>heading 4</h1>
Some stuff


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to