in reply to ref array being modified unexpectively
Yes, there are two things you're overlooking:
In perlsyn you'll see that within a foreach loop, the loop iterator variable ($item) becomes an alias to each element in the array being looped over. So if you modify $item, you modify the corresponding element within the loop's array.
Also, since you're passing a reference to test_ra(), the subroutine is not acting upon a copy of the array referred to by $ra, but rather, the same exact array. In other words, if you were to print scalar $ra and also print scalar $data, you would see that they're the same reference.
Dave
|
|---|