TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ruby, C, and Java are pass-by-value, Perl is pass-by-reference

3 pointsby r11tover 14 years ago

1 comment

gdlover 14 years ago
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.<p><pre><code> $var = shift; // Take the first value passed to the function, copy into $var </code></pre> or<p><pre><code> ($var1, $var2, $var3) = @_ // Copy the first three into $var1, $var2, and $var3 </code></pre> 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.