in reply to replacing text you have already replaced...
I always use 1 while s///;, but you can also get that behavior with only using s///;:
my $data = "aaaaaaaaaaaaaaaaaaaaaaa"; # 23 a's $data =~ s/aa/pos() = print a/ge; print $data;
This outputs a in stead of aaaaaaaaaaaa
pos() normally returns the position where the regexpr matched the last time. Normally the s/// operator leaves of at that position. By using pos() as a lvalue you can reset this position. Therefore the s/// operator starts all over, mimmicking the 1 while s///g behavior.
I wouldn't use this under normal circumstantions though, since this is kind of a obfu. ;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: replacing text you have already replaced...
by suaveant (Parson) on Jul 24, 2001 at 22:24 UTC | |
by Hofmator (Curate) on Jul 25, 2001 at 14:30 UTC | |
|
Re: Re: replacing text you have already replaced...
by Hofmator (Curate) on Jul 25, 2001 at 13:51 UTC | |
by wine (Scribe) on Jul 25, 2001 at 14:00 UTC |