in reply to Re^4: Array value changing for some reason
in thread Array value changing for some reason
$arr[$i] = [reverse @{$arr[$i]}];
assigns a new reference (by creating a new anonymous array) to $arr[$i] replacing the reference copied from @_. Without that reference you can't change the contents of @_
Whereas @{$arr[$i]} = reverse @{$arr[$i]} uses the reference copied from @_ to change the existing array elements.
# $#_[$i] doesn't work
orsub print2DArray { for my $i (0 .. $#_) { for my $j (0 .. $#{$_[$i]}){ print $_[$i][$j]," "; } print "\n"; } }
pojsub print2DArray7 { for (@_) { print join " ",@$_; print "\n"; } }
|
---|
In Section
Seekers of Perl Wisdom