perl's Favorite Default: $_

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了perl's Favorite Default: $_相关的知识,希望对你有一定的参考价值。

If you omit the control varibele from the beiginning of foreach loop, Perl uses its favrorite default variable $_. This is (mostly) just like any other scalar variable, except for its unusual name. For example:

 

foreach (1..10) { #use $_ by default
  print "I can count to $_!\n"; 
}

Althongh this isn‘t Perl‘s only default by a long shot, it‘s Perl‘s most common default. You will see many other cases in which Perl will automatically use $_ when you don‘t tell it to use some other variable or value, thereby saving the programmer from the heavy labor of having to thinking up and type a new variable name. So as not to keep you in suspense, one of those case is print, which will print $_ if given no other argument:

$_ = "yaboo dabba doo";
print;  #print $_ by default

 

From p54 of the book named Learning Perl

 

loop 圈,环,回来。在程序语言里,应该译为“循环”,比如for循环。

scalar 数量,标量。在perl里,就是指的这种数据类型,singular,区别于列表(list)。

not by a long shot 绝不、远没有

in suspense  悬而未决,处于焦灼等待状态,心神不宁;吊胃口

以上是关于perl's Favorite Default: $_的主要内容,如果未能解决你的问题,请参考以下文章

攻防世界 favorite_number mfw[BJDCTF2020]ZJCTF,不过如此

攻防世界: web favorite-number

How Tame Impala Became Rap’s Favorite Rock Band

ABC200 C - Ringo‘s Favorite Numbers 2 思维+map计数

米其林三星餐厅Victor's Fine Dining by christian bau(PERL-NENNIG摩泽尔)

1045 Favorite Color Stripe(LCS解法) 需再理解