zoukankan      html  css  js  c++  java
  • 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 $_!
    "; 
    }

    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  悬而未决,处于焦灼等待状态,心神不宁;吊胃口

  • 相关阅读:
    面向对象知识点2
    面向对象知识点1
    面向对象知识点
    常用模块
    模块与包
    迭代器相关知识
    jquery.jqprint-0.3.js打印功能 以及页眉页脚设置显示与否
    js和layerjs配合实现的拖拽表格列
    iframe中跳转页面的区别
    select3搜索下拉树
  • 原文地址:https://www.cnblogs.com/liulele/p/5906411.html
Copyright © 2011-2022 走看看