in reply to Re^4: Global substitution and report
in thread Global substitution and report

There are two possible workarounds:

A string eval, e.g.

my $subst = 'lc $1'; # and later $str =~ s{$pattern}{push @pos, pos $str; eval $subst; }eg

The other one moves the push to the regex:

use strict; use warnings; use Data::Dumper; my @pos; my $str = "foobarbaz"; if ($str =~ s{([aeiou]+)(?{ push @pos, pos $str })}{<--$1-->}g){ print Dumper \@pos; print $str, "\n"; }

But please read the notes in perlre on the (?{...}) construct.

Replies are listed 'Best First'.
Re^6: Global substitution and report
by Outaspace (Scribe) on Aug 27, 2007 at 12:03 UTC
    Yes the second workaround is exactly what I needed

    Thanks