: ### Does not work.... want to count the number of matches...
: $regex= ($test=~ s/(dav)/$i++ $1/eig);
:
: print "$regex $i\n";
:
: ### This does work..
: $regex= ($test=~ s/(dav)/$1 Smith/ig);
:
: print "$regex\n";
:
: __END__
:
:
: It looks like $regex contains the number of matches,
: what I wanted to was capture the modified string
s/// modifies the string $test and returns the number of times the
replacement succeeded. So $regex would have the number of matches in
it, while $test is the modified string.
: Also can some provide an example of how to use the 'e' switch in
: a regrex,
For your first example, where it looks like you want to replace every
occurance of "dav" with "0 dav", "1 dav", etc:
$test=~ s/(dav)/$i++ . " " . $1/eig;
or
$test=~ s/(dav)/join(" ", $i++, $1)/eig;
or
$test=~ s/(dav)/sprintf("%d %s", $i++, $1)/eig;
In other words, the replacement string needs to be a perl expression.
-- tdk