On Jun 30, 2014, at 12:17 PM, Sunita Pradhan wrote:

> Thanks Jim. It is working but why a array is required here? 
> 

Please respond to the list and not to me personally. That way, everybody will 
see your question, and somebody else can answer.

> > 
> > Try this:
> > 
> > $c = () = $line =~ /\b$w\b/g;

The empty array is necessary to put the return value of the binding operator 
'=~' into list context. Without it, the return value is in scalar context and 
returns just a 1 ('true'). In list context, the binding operator returns a list 
of the matched strings. When that is converted to scalar context by the 
assignment to $c, it becomes the size of the list.

See 'perldoc perlop', search for "Regexp Quote-Like Operators", and scroll down 
to the section titled 'Matching is list context'.


--
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