$ext{$1} += (m/([^.]+)$/);
means something close to
$ext{$1} = $ext{$1} + (m/([^.]+)$/);
Well, actually more like the following, but it doesn't matter for this discussion:
alias $temp = $ext{$1};
$temp = $temp + (m/([^.]+)$/);
Either way, you are relying on Perl evaluating the RHS of the "+=" operator before its LHS, and that's not how Perl operates. In fact, Perl doesn't document how it operates in this circumstance, and that's the reason it's generally a no-no to change and use the same variable in the same expression.
Even though my earlier explanation was wrong, the solutions I posted still avoid the problem.
Update: Improved phrasing by inlining footnotes.
|