Perl 中的 my函数

首页 / Perl入门教程 / Perl 中的 my函数

描述

此函数声明LIST中的变量在包围式块内按词法范围。如果指定了多个变量,则所有变量都必须用括号括起来。

语法

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

链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-my.html

来源:LearnFk无涯教程网

my LIST

返回值

此函数不返回任何值。

以下是显示其基本用法的示例代码-

无涯教程网

#!/usr/bin/perl -w

my $string = "We are the world";
print "$string\n";
myfunction();
print "$string\n";

sub myfunction {
   my $string = "We are the function";
   print "$string\n";
   mysub();
}
sub mysub {
   print "$string\n";
}

执行上述代码后,将产生以下输出-

We are the world
We are the function
We are the world
We are the world

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

人工智能基础课 -〔王天一〕

赵成的运维体系管理课 -〔赵成〕

编译原理实战课 -〔宫文学〕

To B市场品牌实战课 -〔曹林〕

说透区块链 -〔自游〕

郭东白的架构课 -〔郭东白〕

徐昊 · TDD项目实战70讲 -〔徐昊〕

深入浅出可观测性 -〔翁一磊〕

高并发系统实战课 -〔徐长龙〕

好记忆不如烂笔头。留下您的足迹吧 :)