Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

meaning of =()=

by Anonymous Monk
on Jan 04, 2010 at 17:29 UTC ( #815606=perlquestion: print w/ replies, xml ) Need Help??
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.

Comment on meaning of =()=
Re: meaning of =()= (idiom)
by toolic (Chancellor) on Jan 04, 2010 at 17:33 UTC
Re: meaning of =()=
by zentara (Archbishop) on Jan 04, 2010 at 17:34 UTC
Re: meaning of =()=
by ikegami (Pope) 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 =()=
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/

      Interesting link. What the prolific Peteris Krumins has dubbed the turtle operator I called Baby Cart in my recent golf article, following BooK's original suggestion.

      I guess whether @{[]} more closely resembles a turtle or a Baby Cart is a matter of personal taste. Maybe we'll end up with synonyms for this operator. I prefer BooK's Baby Cart because I find it more amusing for some reason, perhaps because this term is not in common usage, at least not in Australia, where we call it a pram.

        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 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 =()= 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]

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://815606]
Approved by toolic
Front-paged by biohisham
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (15)
As of 2014-10-21 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (106 votes), past polls