I have some code that grabs the "between" of some text;
specifically, between a foo $someword
and the next foo $someword
.
However, what happens is it gets stuck at the first "between" and somehow the internal string position doesn't get incremented.
The input data is a text file with newlines here and there: they are rather irrelevant, but make printing easier.
my $component = qr'foo (\w+?)\s*?{';
while($text =~ /$component/sg)
{
push @baz, $1; #grab the $someword
}
my $list = join( "|", @baz);
my $re = qr/$list/; #create a list of $somewords
#Try to grab everything between the foo $somewords;
# or if there's no $foo someword, grab what's left.
while($text=~/($re)(.+?)foo ($re|\z|\Z)/ms)
#if I take out s, it doesn't repeat, but nothing gets grabbed.
{
# print pos($text), "\n"; #this is undef...that's a clue I'm certain.
print $1, ":", $2; #prints the someword and what was grabbed.
print "\n", '-' x 20, "\n";
}