while (<$in>) { s/\band\b/$word/ig; # <- Here you make all the substitutions while (/\band\b/ig) # <-... and here nothing happens! { ++$count; } print($out "$_\n"); }
s/// will return the number of occurrences, so...
while (<$in>) { $code = s/\band\b/$word/ig; # <- Here you make all the substit +utions ## UPDATE: ## $code += s/\band\b/$word/ig; # <- Here you make all ## Sorry for the mistake (thanks blazar!) print($out "$_\n"); }
should works
citromatik
In reply to Re: Counting instances of words
by citromatik
in thread Counting instances of words
by scarymonster
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |