--- David Gilden <[EMAIL PROTECTED]> wrote:
> $test = "dave David Davy";
>
> ### Does not work.... want to count the number of matches...
> $regex= ($test=~ s/(dav)/$i++ $1/eig);
Just counting? Don't use s///. Try this:
my @regex = $test =~ /(dav)/g; # returns list of all matches
$i = scalar @regex;
if you want to get all of them, make sure you add i
my @regex = $test =~ /(dav)/gi; # case insensitive
Also, if you wanted to do it more the way you originally had it, try:
$regex= ($test=~ s/(dav)/$i++,$1/eig);
I added a comma operator, which evaluates it's left hand expression,
throws away the result, then evaluates and returns its right hand
expression.
> print "$regex $i\n";
What were you expecting in $regex here?
> ### 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
Since you did a s///, $test was actually modified.
To get the modified version of the string in $regex, copy it first,
then modify *it*.
> $test = "dave David Davy";
$regex = $test;
$i = $regex = =~ s/(dav)/$1/ig;
> Also can some provide an example of how to use the 'e' switch in
> a regrex,
/e means to return the result of an expression. Let's uppercase that
one oddball "dave", shall we?
$test =~ s/(dav)/ucfirst $1/e;
This makes the replacement string whatever was returned from the
expression; the extression was a ucfirst function call, which
uppercases the first character of it's argument, in this case $1, which
contains "dav". I didn't globalize it, but you could.
> Thanks
> Dave
You're welcome. =o)
Hope it helps.
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/