Learning Perl: 4.2. Invoking a Subroutine

来源:互联网 发布:常州软件培训机构 编辑:程序博客网 时间:2024/06/08 06:16
Previous Page
Next Page

 

4.2. Invoking a Subroutine

Invoke a subroutine from within any expression by using the subroutine name (with the ampersand):[§]

[§] And frequently a pair of parentheses, even if empty. As written, the subroutine inherits the caller's @_ value, which we'll be discussing shortly. So don't stop reading here, or you'll be writing code with unintended effects.

    &marine;  # says Hello, sailor number 1!    &marine;  # says Hello, sailor number 2!    &marine;  # says Hello, sailor number 3!    &marine;  # says Hello, sailor number 4!

Most often, we refer to the invocation as calling the subroutine.

Previous Page
Next Page
原创粉丝点击