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

Hello Monks, Learning to use assignment operators and came across ".=" . Did a lot of googling but couldn't exactly nail down what this means and how it can be used in a perl script. I'd greatly appreciate if some one can point me in the right direction. Thanks.

Replies are listed 'Best First'.
Re: Assignment Operator
by davido (Cardinal) on Mar 18, 2016 at 03:39 UTC

    It's unfortunate that operators are so hard to search for. Search engines really ought to point you to perlintro, or perlop, both of which discuss the dot and the dot-assignment operators.

    The dot operator catenates two strings:

    my $foo = "bar" . "baz"; print $foo, "\n";

    ...prints "barbaz". The .= operator does the same thing, but assigns the new string to the scalar on the left.

    my $foo = "bar"; $foo .= "baz"; print $foo, "\n";

    ...also prints "barbaz".


    Dave

Re: Assignment Operator
by MidLifeXis (Monsignor) on Mar 18, 2016 at 11:17 UTC

    $foo .= $bar is shorthand for $foo = $foo . $bar. The appropriate links for the dot operator have been given above.

    --MidLifeXis

Re: Assignment Operator
by Anonymous Monk on Mar 18, 2016 at 01:26 UTC