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

Re^5: grep for hash?

by Fletch (Bishop)
on Jul 07, 2009 at 16:34 UTC ( [id://777934]=note: print w/replies, xml ) Need Help??


in reply to Re^4: grep for hash?
in thread grep for hash?

It's not explicitly documented but it's stated in perlsyn that the assignment operator works "as in C", and it has the same right-to-left associativity as C's, and the value of the assignment is itself a valid rvalue for another subsequent assignment. Granted it's not chiseled into stone tablets, but I don't think that it's a "ZOMGWTFBBQ no one knows what'll happen just don't do that" case like ++$a + $a++ is.

That being said, your alternative with the separate assignment before use is definitely a clearer implementation.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^6: grep for hash?
by ikegami (Patriarch) on Jul 07, 2009 at 16:38 UTC

    it has the same right-to-left associativity as C's

    Operator associativity is not related to operand evaluation order.

    Perl even have a case where they differ. Exponentiation is right-associative, but its operands are evaluated from left to right.

    it's stated in perlsyn that the assignment operator works "as in C"

    Operand evaluation order is not defined in C, and different compilers use different orders. (Well, so I was told.)

    but I don't think that it's a "ZOMGWTFBBQ no one knows what'll happen just don't do that

    I agree. Especially since my $x = $x; relies on it.

      That's one I didn't know; a new corner case to file away.

      $ perl -le 'print +(do{ print STDERR "ORLY?"; 2})**(do{ print STDERR " +YARLY!"; 3})' ORLY? YARLY! 8

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://777934]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-03-28 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found