07/05/01 22:23:56
\Gは置換文では使わないほうがいいよ。代入されるとposがリセットされてしまうから
あとを置換しながらposを保持することはできないのでコピーを作ることを考えてみては
自分ならこう書く
my $replaced_text;
pos $text = 0;
while (pos $text < length $text) {
if ($text =~ m/\G $regexp/gcsx) {
# ここで入力による分岐処理を行う
}
elsif ($text =~ m/\G(.+?) (?=$regexp)/gcsx) {
$replaced_text .= $1;
}
else {
$text =~ m/\G (.*)/gcsx;
$replaced_text .= $1;
}