加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl的变量@_

发布时间:2020-12-16 00:39:18 所属栏目:大数据 来源:网络整理
导读:这个变量很神奇。 @_ is the list of incoming parameters to a sub. So if you write a sub,you refer to the first parameter in it as $_[0] ,the second parameter as $_[1] and so on. And you can refer to $#_ as the index number of the last param

这个变量很神奇。

@_ is the list of incoming parameters to a sub. So if you write a sub,you refer to the first parameter in it as $_[0],the second parameter as $_[1] and so on. And you can refer to $#_ as the index number of the last parameter。

?

@_是子程序的一个私有变量◆;如果有一个全局变量@_,它将在此子程序调用前存储起来,当子程序调用完成后,其早期的值会被重新赋还给@_◆。这意味着当将参数传递给子程序时不用担心它会影响此程序中其它子程序的@_这个变量的值。嵌套的子程序调用时,@_的值和上述类似。甚至此子程序递归调用时,每一次调用将得到新的@_,因此子程序调用时将得到其自身的参数列表。

我在别的地方看到这样一个程序:用hash表建立了二叉树的关系,然后在子程序中递归调用,从而左序遍历输出各个节点的例子,巧妙的使用了变量@_,将第一次调用的参数放在下标为0的该数组内,第二次调用的参数放在下标为1的数组内。以此类推。以下是代码:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读