You have pointed out well that I drafted that sample code too quickly. I have used similar code in other projects, but in this project I had in mind to do the substitution for the entire array…and that caused the Freudian? slip with that. I did not mean to structure the nested loop to act on the entire array with each substitution. It should have looked more like:
@array = @array2; @array2 = (); foreach $line (@array) { $count = $line =~ s/\b$oldline\b/$spliced/eg; $totalcount += $count; push @array2, $line; }
I had assumed that the variable on the replacement side would need to be evaluated, but it appears you are correct and the "e" is unnecessary. Removing that has sped up the script by about 3%. I learned something. Thank you!
In reply to Re^4: How to count substitutions on an array
by Anonymous Monk
in thread How to count substitutions on an array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |