我的($ variableName)和我的$ variableName在Perl中有什么区别? [英] What's the difference between my ($variableName) and my $variableName in Perl?

查看:60
本文介绍了我的($ variableName)和我的$ variableName在Perl中有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Perl中的my ($variableName)my $variableName有什么区别?括号是做什么的?

What's the difference between my ($variableName) and my $variableName in Perl? What to the parentheses do?

推荐答案

重要的作用是在声明变量的同时初始化变量:

The important effect is when you initialize the variable at the same time that you declare it:

my ($a) = @b;   # assigns  $a = $b[0]
my $a = @b;     # assigns  $a = scalar @b (length of @b)

另一个重要的时刻是声明多个变量.

The other time it is important is when you declare multiple variables.

my ($a,$b,$c);  # correct, all variables are lexically scoped now
my $a,$b,$c;    # $a is now lexically scoped, but $b and $c are not

如果您use strict,最后一条语句将给您一个错误.

The last statement will give you an error if you use strict.

这篇关于我的($ variableName)和我的$ variableName在Perl中有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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