Important nit-pik: You mean parentheses, (or "parens" for short.) "Brackets" refers to []. An important difference when discussing code.
To answer the question, Perl functions can return different values depending on their context. In this case, the matching regex operator can return either a list, or a scalar. (see perlre for details). In list context, the matching regex will return the contents of parenthesized patterns. /(\d)/ puts the first digit in $1. /(\d)(\d+)/ puts the first digit in $1, and all others in $2. Be careful when using this, however, since these values will not be what you expect if the pattern doesn't match. In list context, the $1, $2, ...$N variables are returned as a list.
Thus, $count =~ /^(\d+)/ would return a boolean indicating whether a match occured. ($count) =~ /^(\d+)/ would return either undef (if no match occured) or the list ($1) (which then gets the value of $1 assigned to $count)
In reply to Re: why the need to match when assigning?
by swiftone
in thread why the need to match when assigning?
by slok
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |