Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^5: Array value changing for some reason

by poj (Abbot)
on Jan 01, 2019 at 16:34 UTC ( [id://1227881]=note: print w/replies, xml ) Need Help??


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
sub print2DArray { for my $i (0 .. $#_) { for my $j (0 .. $#{$_[$i]}){ print $_[$i][$j]," "; } print "\n"; } }
or
sub print2DArray7 { for (@_) { print join " ",@$_; print "\n"; } }
poj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1227881]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found