in reply to count words in a line
@sentence = split /\s/,"perlmonk perlmonk perlmonk "; $numWords = @sentence;
The last one would be more tricky, but it can be done with a fairly easy regxp... something along the lines of /p\s*e\s*..... should do the trick@sentence = split /\s/,"perlmonk perlmonk perlmonk and some other wor +ds that are not perlmonk"; foreach $word (@sentence) { if ( $word =~/perlmonk/) { $numOccur++; } }
|
|---|