in reply to strange behavior of parenthesis

In list context the =~ operator returns the catched parts (those in between braces in the regex). In scalar context it returns the number of catched parts.

The braces around $func induce list context. Should be clear now, no?


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: strange behavior of parenthesis
by broquaint (Abbot) on Jul 11, 2005 at 11:12 UTC
    Further to that, you can find this documented in perlop under the m/PATTERN/cgimosx subsection of the Regexp Quote-Like Operators section:
    If the /g option is not used, perlop in a list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, i.e., ($1, $2, $3...). (Note that here $1 etc. are also set, and that this differs from Perl 4's behavior.) When there are no parentheses in the pattern, the return value is the list (1) for success. With or without parentheses, an empty list is returned upon failure.
    HTH

    _________
    broquaint

Re^2: strange behavior of parenthesis
by mosh (Scribe) on Jul 11, 2005 at 11:00 UTC
    So, it catches only the (.*) ?
    How come ?

      So, it catches only the (.*) ?

      What else?

      Dodge This!