Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-06-18 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (109 votes). Check out past polls.

    Notices?