I think you're trying to go about this in a weird way, where what you really want is to do successive matches against a string, finding a marker (the A~~~blah~A part) and then the stuff that occurred up to the marker. The whole "match something then erase what you just matched" is kinda strange, as it's much easier to just find what you want, stick it into a separate variable (where you can fold-spindle-and-mutilate as much as you want) without having to mess with the original string itself. Maybe something like this?
#!usr/bin/perl
my $sentence = " he PP
study VB
A~~~language~A NP
and CC
play VB
A~~~game~A NP
.";
while ($sentence =~ m/(.*?)A~~~(.*?)~A/sg) {
my $before_marker = $1;
my $marker = $2;
print "Before marker is: $before_marker\n";
print "The marker is: $marker\n\n";
# Do stuff with $before_marker and $marker
}
which will produce:
Before marker is: he PP
study VB
The marker is: language
Before marker is: NP
and CC
play VB
The marker is: game
Does this get at what you're trying to do? If not, post some more details as to what you really want, as I suspect everyone's a little confused right now.
Gary Blackburn
Trained Killer
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.