What does += mean in perl?

Recommended Answers

All 3 Replies

$x += $y

means the same thing as

$x = $x + y

with the exception that $x is evaluated only once -- this would only make a difference if evaluating $x had side effects (e.g. when it's not really a variable but actually a subroutine call).

You can use the same op= syntax for any of Perl's operators, like *=, -=, /=, <<=, .=, etc. and the semantics are the same.

Hi Trentacle,
I suppose you really want to write:

   $x = $x + $y;

instead of

$x = $x + y

Hi tunisia,
In addition to what Trentacle wrote you could read **Assignment Operators ** under

     perldoc perlop 

documentation from your Command Line Interface.

Quite so. Thanks for catching my mistake.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.