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

  • 相关阅读:
    正则
    springboot整合rabbitmq(fanout广播模式)
    docker 安装rabbitmq
    centos7安装rabbitmq
    rabbitmq报错{:query, :rabbit@master1, {:badrpc, :timeout}}
    Linux永久修改hostname
    thread dump日志文件分析
    模板方法模式
    装饰器模式
    springboot集成redis,压测报错;
  • 原文地址:https://www.cnblogs.com/liulele/p/5906411.html
Copyright © 2011-2022 走看看