in reply to Pass array, then clear
you're creating a new variable that happens to contain an array ref defined in the caller. Then you simply give another value (namely a reference to an empty array) to that variable. There should not be any reason why this would modify the original array ref.my($data) = @_;
Just as if you say:
this will not change the value of $c.my $c = 5; my $d = $c; $d = 6;
In the commented out version, something else is happening: @$data is actually the array referred to by $data, so you are not modifying the local variable just created in the sub, but the value (the anonymous array referred to by the array ref) $data refers to.
|
---|