Hacker News new | past | comments | ask | show | jobs | submit login
Ruby, C, and Java are pass-by-value, Perl is pass-by-reference (advogato.org)
3 points by r11t on Oct 3, 2010 | hide | past | favorite | 1 comment



The 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: