#!/usr/bin/perl
my $block = <<EOF;
Title1
text1
text2
Title2
text3
text4
EOF
my @sp = split(/Title\d/, $block);
foreach my $i (@sp)
{
chomp($i);
print "$i\n-------------------";
}
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of Peter Gordon
Sent: Wednesday, December 24, 2008 1:41 PM
To: Perl in Israel
Subject: [Israel.pm] Regex question
Suppose I have the following code
my $text =<<EOF;
Title1
text1
text2
Title2
text3
text4
EOF
@blocks = $text =~ m!(^Title\S+.*?)(?=^Title|\Z)!mgs ;
The idea is to split the text into blocks. This code works, but the
lookahead requires repeating part of the first half of the regex.
Is there a shorter regex, without the repetition, that can do the same
thing?
Peter
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl