Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Changing an array from a sub

by rizzo (Deacon)
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 -

Replies are listed 'Best First'.
Re^2: Changing an array from a sub
by harangzsolt33 (Friar) 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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2022-10-01 02:55 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (126 votes). Check out past polls.