in reply to why the need to match when assigning?

The line means "match this regular expression against $ARGV[0] and assign any captured values to ($count)".

The regular expression looks for one or more digits at the start of the string. The \d+ is in parenthesis so the digits are captured into the special variable $1.

In scalar context the match operator returns true or false depending on whether the match succeeds or not. In list context, it returns the values of the match variables $1, $2, etc. The parenthesis around $count forces the assignment into list context. The nett result is that the set of digits that were matched at the start of $ARGV[0] ends up in $count.

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

  • Comment on Re: why the need to match when assigning?