Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Changing an array from a sub

by harangzsolt33 (Beadle)
on Feb 14, 2018 at 06:28 UTC ( #1209105=note: print w/replies, xml ) Need Help??

in reply to Re: Changing an array from a sub
in thread Changing an array from a sub

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209105]
and dust plays in a shaft of sunlight...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2018-03-24 15:04 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (299 votes). Check out past polls.