in reply to How come @_ gets changed here?

That is doubly confusing code ...

2 effects are overlaying.

Since you reassign these elements with the map, you are effectively changing @_, it's like writing @_ = map { 2 * $_ } @_;

Change this to my @arr = map { 2 * $_ } @_; and your problem disappears

Style tips how to avoid this

  • it's always a good strategy to choose meaningful names for variables instead of arr or array , like this strict would have caught the error.
  • don't declare variables on top of your program if you only intend to use them much later.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!