Perl 使用特殊字符 & [英] Perl using the special character &

查看:80
本文介绍了Perl 使用特殊字符 &的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题.我正在阅读一些代码,因为我的学校没有教我任何关于 perl 编程的有用信息,所以我在这里问你们.我看到在某些 perl 程序中经常使用此行:

I had a small question. I was reading some code and as my school didn't teach me anything useful about perl programming, I am here to ask you people. I see this line being used a lot in some perl programs:

$variable = &something();

我不知道 & 符号在这里意味着什么,因为我从未在 perl 中说过.而 something 是一个子程序(我猜).它通常说一个名字,有时它也有像函数一样的参数.谁能告诉我 & 在这里代表什么以及 something 是什么.

I don't know what the & sign means here as I never say it in perl. And the something is a subroutine ( I am guessing). It usually says a name and it has arguments like a function too sometimes. Can someone tell me what & stands for here and what that something is all the time.

该变量接受某种返回值,然后用于检查某些条件,这让我认为它是一个子程序.但为什么是 &?

The variable takes in some sort of returned value and is then used to check some conditions, which makes me think it is a subroutine. But still why the &?

谢谢

推荐答案

在旧版本的 perl 中,& 用于调用子程序.现在这不是必需的,\& 主要用于将 reference 带入子程序,

In older versions of perl & was used to call subroutines. Now this is not necessary and \& is mostly used to take a reference to subroutine,

my $sub_ref = \&subroutine;

或者忽略函数原型(http://perldoc.perl.org/perlsub.html#原型)

除了用于引用子程序的 &bitwise and 运算符,

Other than for referencing subroutines & is bitwise and operator,

http://perldoc.perl.org/perlop.html#Bitwise-And

这篇关于Perl 使用特殊字符 &的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆