larry*wei 2010-12-30 14:42 采纳率: 0%
浏览 433
已采纳

在 Perl 中@的意思是什么?

What is the meaning of @_ in Perl?

转载于:https://stackoverflow.com/questions/4563485/what-is-the-meaning-of-in-perl

  • 写回答

9条回答 默认 最新

  • 程序go 2010-12-30 14:47
    关注

    perldoc perlvar is the first place to check for any special-named Perl variable info.

    Quoting:

    @_: Within a subroutine the array @_ contains the parameters passed to that subroutine.

    More details can be found in perldoc perlsub (Perl subroutines) linked from the perlvar:

    Any arguments passed in show up in the array @_ .

    Therefore, if you called a function with two arguments, those would be stored in $_[0] and $_[1].

    The array @_ is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable).

    If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array @_ removes that aliasing, and does not update any arguments.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致