Using ampersands and parens when calling a Perl sub

前端 未结 3 886
粉色の甜心
粉色の甜心 2021-02-13 09:28
#!/usr/bin/perl

sub t {
  print \"in t\\n\";
  print \"@_\\n\";
  &s;
}

sub s {
  print \"in s\\n\";
  print \"@_\\n\";
}

t(1,2);
print \"out\\n\";
print \"@_\\n\         


        
3条回答
  •  我寻月下人不归
    2021-02-13 10:26

    Straight from the camel's mouth:

    If a subroutine is called using the ``&'' form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid.

提交回复
热议问题