On May 23, David Gilden said:
>#!/usr/bin/perl
>
>$test = "dave David Davy";
>
>$i=0;
>
>### Does not work.... want to count the number of matches...
>$regex= ($test=~ s/(dav)/$i++ $1/eig);
>
>print "$regex $i\n";
Do you want to count matches, or change the string? If you just want to
count the number of matches, use m//g in a while loop:
$count++ while $test =~ m/dav/g;
>Also can some provide an example of how to use the 'e' switch in
>a regex,
If you want to change "dave danny Davy" to "1dave danny 2Davy", then you
can do:
$test =~ s/dav/++$i . "dav"/gie;
Since the RHS (right-hand side) is evaluated as Perl code (due to the /e
modifier), you have to make sure it's valid Perl.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **