当前位置: 首页 > 文档资料 > Perl 入门教程 >

sub

优质
小牛编辑
124浏览
2023-12-01

描述 (Description)

该函数定义了一个新的子程序。 上面显示的参数遵循这些规则 -

  • NAME是子例程的名称。 可以使用或不使用原型规范预先声明已命名的子例程(没有关联的代码块)。

  • 匿名子例程必须有一个定义。

  • PROTO定义函数的原型,在调用函数以验证提供的参数时将使用该函数。

  • ATTRS为解析器定义有关正在声明的子例程的附加信息。

语法 (Syntax)

以下是此函数的简单语法 -

sub NAME PROTO ATTRS BLOCK# Named, prototype, attributes, definition
sub NAME ATTRS BLOCK # Named, attributes, definition
sub NAME PROTO BLOCK # Named, prototype, definition
sub NAME BLOCK # Named, definition
sub NAME PROTO ATTRS # Named, prototype, attributes
sub NAME ATTRS # Named, attributes
sub NAME PROTO # Named, prototype
sub NAME # Named
sub PROTO ATTRS BLOCK # Anonymous, prototype, attributes, definition
sub ATTRS BLOCK # Anonymous, attributes, definition
sub PROTO BLOCK # Anonymous, prototype, definition
sub BLOCK # Anonymous, definition

返回值 (Return Value)

此函数不返回任何值。

<!--

例子 (Example)

Following is the example code showing its basic usage −

When above code is executed, it produces the following result −

-->