TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

3 点作者 r11t超过 14 年前

1 comment

gdl超过 14 年前
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.