Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Changing an array from a sub

by rizzo (Monk)
on Feb 14, 2018 at 05:30 UTC ( #1209103=note: print w/replies, xml ) Need Help??


in reply to Changing an array from a sub

'Also, what's the best way to deal with arrays?'

Probably not always the best way, but sometimes handy comes the map-function:

map - perldoc.perl.org

Replies are listed 'Best First'.
Re^2: Changing an array from a sub
by harangzsolt33 (Beadle) on Feb 14, 2018 at 06:28 UTC
    Thank you very much for all your answers! I come from a JavaScript background, and in JavaScript when you make a function call, a copy of each variable is passed to the function, but if the variable is an array, then only a reference is passed. So, writing to that array will change the original array as well. It's confusing when you combine it with perl. Lol But I am trying to sort it out.
    // The only way to work with arrays in JavaScript: myArray = [0, 1, 2, 3, 4]; ChangeArrayJS(myArray); function ChangeArrayJS(ARRAY) { ARRAY[2] = 'JS'; // changes myArray var COPY_OF_ARRAY = ARRAY; COPY_OF_ARRAY[2] = 'this will be lost'; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209103]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-05-24 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?