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:

..) { #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: $_的更多相关文章

  1. perl学习之:@_ $_

    question 1 :数组@xxx调用时,每个元素应该用$xxx[0]/$xxx[1]...   来表示所以$_[0]表示@_的一个元素,和默认缺省变量$_无关,是两个东西请查阅数组元素调用相关章节 ...

  2. Perl 语法 - 基础

    perl语言的核心是正则表达式,在文本处理上非常有优势,与python类似,但语法不同,perl的语法很灵活,用多了才会觉得好用. 常用知识点总结: perl语法类似于C语言(perl源于Unix), ...

  3. Perl一行式:选择行输出、删除、追加、插入

    perl一行式程序系列文章:Perl一行式 对于Perl的一行式perl程序来说,选择要输出的.要删除的.要插入/追加的行是非常容易的事情,因为print/say决定行是否输出/插入/追加/删除.虽然 ...

  4. Perl一行式:文本编解码、替换

    perl一行式程序系列文章:Perl一行式 文本大小写转换 全部字符转换成大写或小写,有几种方式: # 转大写 $ perl -nle 'print uc' file.log $ perl -ple ...

  5. Perl的列表和数组

    列表和数组 列表 使用括号包围的元素,括号中的元素使用逗号隔开的是列表. 列表中的元素可以是字符串.数值.undef或它们的混合. 列表中的字符串元素需要使用引号包围. 空列表是括号中什么都没有的列表 ...

  6. Perl基础速成

    本文是针对没有Perl基础,但想用perl一行式命令取代grep/awk/sed的人,用于速学Perl基础知识. Perl一行式系列文章:Perl一行式程序 perl的-e选项 perl命令的-e选项 ...

  7. perl选项、特殊变量、一些函数参考手册

    perl一行式程序系列文章:Perl一行式 本文用来收集Perl一行式中涉及到的一些选项.特殊变量的说明,可以用来做速查手册. 本文会逐渐更新. 第一次学Perl一行式时,请直接忽略本文内容,并直接从 ...

  8. Perl一行式:处理空白符号

    perl一行式程序系列文章:Perl一行式 假如文件file.log内容如下: root x 0 0 root /root /bin/bash daemon x 1 1 daemon /usr/sbi ...

  9. Perl一行式:处理行号和单词数

    perl一行式程序系列文章:Perl一行式 所有行的行号 $ perl -pe '$_ = "$. $_"' file.log $ perl -ne 'print "$. ...

随机推荐

  1. 【欧拉计划4】Largest palindrome product

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/1371281760.html 原创:[欧 ...

  2. winform实现动态按钮

    private void button6_MouseMove(object sender, MouseEventArgs e) { button6.ImageAlign = ContentAlignm ...

  3. 设计模式20---设计模式之备忘录模式(Memento)(行为型)

    1.讲解备忘录模式 备忘录模式(Memento Pattern)又叫做快照模式(Snapshot Pattern)或Token模式,是GoF的23种设计模式之一,属于行为模式. 1.1定义 在不破坏封 ...

  4. fastcgi重启

    重启nginx和php-cgi 的命令 nginx: sudo /etc/init.d/nginx restart 同样也可以有start,stop等参数php-cgi: 先杀死进程sudo kill ...

  5. (转)cin、cin.get()、cin.getline()、getline()、gets()等函数的用法

    学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结,为了自己复习,也希望对后来者能有所帮助,如果有差错的地方还请各位多多指教(本文所有程序均通过VC 6.0运行)转载请保留作者信息:1.cin1 ...

  6. easyui datagrid自定义操作列

    通过formatter方法给Jquery easyui 的datagrid 每行增加操作链接 我们都知道Jquery的EasyUI的datagrid可以添加并且自定义Toolbar, 这样我们选择一行 ...

  7. 在Visual Studio 2012中使用VMSDK开发领域特定语言1

    在Visual Studio 2012中使用VMSDK开发领域特定语言(一)   前言 本专题主要介绍在Visual Studio 2012中使用Visualization & Modelin ...

  8. 64位CentOS 6.0下搭建LAMP环境

    系统环境:Centos6.0 x64 1.确认搭建LAMP所需要的环境是否已经安装 [root@centos6 ~]# rpm -q make gcc gcc-c++ zlib-devel libai ...

  9. MSSQL 清空日志 删除日志文件

    MSSQL 清空日志 删除日志文件 最近的项目主要做数据的归档,把数据从一个数据库拉到另一个数据库,照成新数据库的日志文件非常大:于是想把日志文件删除.最简单就是先分离数据库->删除日志文件-& ...

  10. 使用SmsManager服务群发短信

    SmsManager是Android提供的一个非常常见的服务,SmsManager提供了一系列sendXxxMessage()方法用于发送短信,不过短信通常都是普通文本,调用sendTextMessa ...