On Jun 30, 2014, at 11:57 AM, Sunita Pradhan wrote:

> Hi
> 
> I want to count number of occurrences of one word in a line within one single 
> line of perl script .
> 
> My code :
> 
> $c++ if ($line =~ /\s+$w\s+/g);
> print "count $c\n";

Try this:

$c = () = $line =~ /\b$w\b/g;



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to