in reply to counting the number of occurrances of a word using regex
That prints "2".my $str = "The quick brown fox jumped over the lazy dog"; my @the = ( $str =~ /\bthe\b/gi ); print scalar @the, $/;
update: It would be clearer (I hope) to say that "tr///" treats every character in the left-hand side as a member of a character class; it cannot treat any sequence of characters as a contiguous string to be matched; only the "m//" operator (and the "s///" operator) can do that. Look carefully at the "perlop" man page for more complete descriptions of these three operators.
|
|---|