use warnings;
use strict;
my @array = (1,2,3,4,5);
my $v = 1;
sub by_ref
{
my ($array_ref,$v) = @_;
@$array_ref = (0,0,0);
print "Array inside by_ref: @$array_ref\n";
}
by_ref(\@array,$v);
print "Array changed: @$array\n";
I’m passing @array by reference(I’m assuming I’m doing it right). I want the changes made in the sub routine on @arraybe reflected in the calling sub routine. I don’t know where I have gone wrong.
Thank you in advance.
You are printing the array reference outside the subroutine too, which is wrong. The scope of array reference is limited to the subroutine only.
So you should change your last line to print only
@arraynot@$array.Like:
print "Array changed: @array\n";