in reply to Counting instances of words
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting instances of words
by scarymonster (Initiate) on May 25, 2007 at 16:43 UTC | |
by blazar (Canon) on May 25, 2007 at 19:32 UTC |