perl的老地方$_

简介:

foreach 省略了控制变量,Perl就使用他的老地方变量_代替。  [root@Master perl]# less LaoDiFang.pl   #!/usr/bin/perl  foreach (1..10) {    print "I can count to_代替。  [root@Master perl]# less LaoDiFang.pl   #!/usr/bin/perl  foreach (1..10) {    print "I can count to_!\n";
}
[root@Master perl]# perl LaoDiFang.pl 
I can count to 1!
I can count to 2!
I can count to 3!
I can count to 4!
I can count to 5!
I can count to 6!
I can count to 7!
I can count to 8!
I can count to 9!
I can count to 10!
 

[root@Master perl]# less LaoDiFang1.pl 
#!/usr/bin/perl
_ = "Hello LaoDiFang \$_";    print;  print "\n";  [root@Master perl]# perl LaoDiFang1.pl   Hello LaoDiFang_ = "Hello LaoDiFang \$_";    print;  print "\n";  [root@Master perl]# perl LaoDiFang1.pl   Hello LaoDiFang_

打印不指定变量时就答应 $_




本文转自 freeterman 51CTO博客,原文链接:http://blog.51cto.com/myunix/1160205,如需转载请自行联系原作者

目录
打赏
0
0
0
0
265
分享
相关文章
|
10月前
|
|
10月前
|
|
10月前
|
Perl 教程 之 Perl 特殊变量 1
Perl教程介绍了Perl的特殊变量,如预定义的OSERRORuseEnglish)_,_在循环和模式匹配中默认存储当前值。例如,一个foreach循环无需显式指定变量,仍能通过print输出迭代的内容。此外,print使while_也用于存储输入记录。
46 2
|
10月前
|
Perl 教程 之 Perl 特殊变量 2
Perl特殊变量包括全局标量、数组、哈希、文件句柄及常量等,如ARG、@ARGV、%ENV等。它们在不同场景下有特定用途,如!存储系统错误信息,@ARGV保存命令行参数,%SIG处理信号。还有正则表达式变量如$&存储匹配字符串,以及文件句柄如STDIN、STDOUT。这些变量在Perl编程中起到关键作用。
78 2
|
10月前
|