4 ms·
Ruby, C, and Java are pass-by-value, Perl is pass-by-reference
- gdl 16y agoThe interesting bit with Perl is that so many people don't realize it's pass-by-reference because the standard idioms for starting a function copy the aliased "references" by value, which then act just like in any of the other languages. $var = shift; // Take the first value passed to the function, copy into $var or ($var1, $var2, $var3) = @_ // Copy the first three into $var1, $var2, and $var3 Using the aliased variables directly and with the intentional goal of altering the originals is almost unheard of in my experience (excluding some clever bits of magic in a few modules). Even if you want to pass a reference: you'd pass an explicit reference, copy that, then dereference the copy.