http://qs321.pair.com?node_id=427975

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

Hi,

I'm viewing a code. Could somebody explain to me what does .= mean in the statement $hash{$k} .= "{$v}" where $k and $v are key and value of hash.

thanks,
riz

Retitled by davido from 'what does $hash{$k} .= "{$v}" class='add-text' size='.

Replies are listed 'Best First'.
Re: what does $hash{$k} .= "{$v}"
by davido (Cardinal) on Feb 04, 2005 at 08:24 UTC

    It is an assignment and a concatenation all in one. Here are a few other variants:

    $string .= " world."; # Concatenate and assign. Same as... $string = $string . " world."; $num += 5; # Add and assign. Same as... $num = $num + 5; $num -= 5; # Subtract and assign. Same as... $num = $num - 5; $num *= 5; # Multiply and assign. Same as... $num = $num * 5; $num /= 5; # Divide and assign. Same as... $num = $num / 5;

    Dave

Re: what does $hash{$k} .= "{$v}"
by Anonymous Monk on Feb 04, 2005 at 08:05 UTC
    It's an efficient way of writing:
    $hash{$k} = $hash{$k} . "{$v}";
    See man perlop.