in reply to Array of ($1, $2, ...) in replacement part of s///?

You can use the code assertion regex to do this. (See perlre "Extended patterns" for details).

P:\test>perl -Mstrict -wle" my $s = 'the quick brown fox jumps over the lazy dog'; my @bits; $s =~ s[ .(.)(?{ push@bits,$^N }) ..(..)(?{ push@bits,$^N }) .] [ print join'-',@bits; ]gex;" h-qu h-qu-k-ro h-qu-k-ro- -x h-qu-k-ro- -x -m- o h-qu-k-ro- -x -m- o-r-he h-qu-k-ro- -x -m- o-r-he-a- d

Note: I've split the 'one-liner' up to avoid the code wrap mangler.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Timing (and a little luck) are everything!

Replies are listed 'Best First'.
Re: Re: Array of ($1, $2, ...) in replacement part of s///?
by sleepingsquirrel (Chaplain) on Jan 28, 2004 at 21:33 UTC
    This just might be the excuse I was looking for to use the (?{}) construct and friends. But I notice that perlre says...
    WARNING: This extended regular expression feature is considered highly experimental, and may be changed or deleted without notice.
    But there is nary a word about this experimentalism in my 3rd edition Camel. Anyone care to take a guess about its life expectancy? (5.10?, ponie?, 6.0?)
      There may (should) be change in how those constructs interact with lexicals in the code. Otherwise, they aren't going away in any version of perl5.