in reply to Re: Count replaces in search and replace
in thread Count replaces in search and replace

One final comment - perhaps you should consider the += operator? As well, since you are visiting each key-value pair once, each might be appropriate. And, as long as you are using $_, you may way well use its shorthand.

my $YESMapping = 0; while (my ($key, $value) = each %map) { $YESMapping += s/$key/$value/gi; } print "Replaced $YESMapping entries.\n"

Replies are listed 'Best First'.
Re^3: Count replaces in search and replace
by VinsWorldcom (Prior) on Mar 13, 2009 at 01:32 UTC

    Yeah, I realized the += mistake (as in I should have used that) after I had posted it and saw it in front of me. I went back and changed my actual code.

    The "each" recommendation is new to me. I'm certainly not a Perl expert (yet), so I rely on the faithful "foreach" when I want to do something "for each" member of a group. Thanks for the tip, I'll read up on that and try it out.