in reply to count the occurrences of particular word in a file and extract number in ()
how to I count the occurrences of word 'the' in a file?
Per perlfaq4 and with the basic regex \bthe\b to indicate a word boundary as documented in perlre, we get:
- Millermy $data = do {local $/; <DATA>}; my $count = () = $data =~ m/\bthe\b/ig; print $count; __DATA__ Then I played with the rabbit and the thesaurus. (2) It was quite the experience. (1) Seriously, the bunny was the coolest pet in the whole zoo. (3)
|
|---|