http://www.perlmonks.org?node_id=815606

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is there a name for the =()= "operator"? Does it have any further significance beyond returning the number of matches from a regular expression?

I just noticed googling for =()= turns up nothing, it is not mentioned in perlre or perlop (!), and it is usually not listed as an operator anywhere.

Replies are listed 'Best First'.
Re: meaning of =()=
by ikegami (Patriarch) on Jan 04, 2010 at 17:39 UTC
    =()= is not an operator.
    $scalar =()= EXPR
    is a funky way of writing
    $scalar = ( () = EXPR )

    It consists of two operations: a list assignment (() = EXPR) as the RHS of a scalar assignment ($scalar = ...). Both types of assignments are documented in perlop, but the bits that apply are:

    • The RHS of a list assignment is evaluated in list context.
    • The RHS of a scalar assignment is evaluated in scalar context.
    • A list assignment in scalar context returns the number of elements returned by its RHS.

    In short, it's a means of evaluating an expression in list context and returning the number of elements returned instead of the elements themselves.

    See Mini-Tutorial: Scalar vs List Assignment Operator

Re: meaning of =()= (idiom)
by toolic (Bishop) on Jan 04, 2010 at 17:33 UTC
Re: meaning of =()=
by JavaFan (Canon) on Jan 04, 2010 at 18:01 UTC
    Is there a name for the =()= "operator"?
    It's the goatse (secret) operator.
    Does it have any further significance beyond returning the number of matches from a regular expression?
    Of course! It can also be used to find out the number of elements returned by localtime. Or by caller. Or any other function that in scalar context doesn't return the number of elements of what it would return in list context.
      One obscure person cannot rename the flying lentil (hairy lentil) to goatse (secret) operator.
Re: meaning of =()=
by Anonymous Monk on Jan 04, 2010 at 17:42 UTC
    Thanks all. Just found this page too, which seconds the "goatse" name
    http://www.catonmat.net/blog/secret-perl-operators/
        When I invented @{[]}, I neglected to give it a name. Maybe I should have asked Heidi (Larry Wall's daughter), like I did to come up with <=> as "spaceship", which has apparently stuck (having been even in the text of an error message for a while).

        -- Randal L. Schwartz, Perl hacker

        The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Re: meaning of =()=
by zentara (Archbishop) on Jan 04, 2010 at 17:34 UTC
Re: meaning of =()= is flying lentil
by Anonymous Monk on Jan 04, 2010 at 21:50 UTC
    flying lentil
Re: meaning of =()=
by hbm (Hermit) on Jan 06, 2010 at 16:04 UTC

    Eyepatch?

    Rolex?

Re: meaning of =()= (null list accumulator, list counter)
by Anonymous Monk on Aug 05, 2013 at 10:59 UTC

    :)

    In scalar context the null list as lvalue counts (accumulates and returns number of elements )

    $ perl -e " @g=( 1 .. 4 ); $f[0]=()=@g; dd\@f; dd\@g " [4] [1 .. 4]

    In list context the null list as lvalue is null (accumulates and discards )

    $ perl -e " @g=( 1 .. 4 ); @f=()=@g; dd\@f; dd\@g " [] [1 .. 4]