Perl语言学习

  • Here文档
    • 复制代码
      #!/bin/perl
      
      $price=100;
      
      # No quotes around terminator EOF are same # as double quotes
      # Variables are expanded
      print <<EOF1;
      The price1 of $price is right.
      EOF1
      print <<"EOF2";
      The price2 of $price is right.
      EOF2
      
      # The variable is not expanded if terminator is enclosed in single quotes
      print <<'FINISH';
      The price of $price is right.
      FINISH
      
      # If terminator is in backquotes, # will execute UNIX commands
      print <<`END`;
      echo hi there
      echo -n "The time is "
      date
      END
      View Code
      复制代码
    • 输出:
      The price1 of 100 is right.
      The price2 of 100 is right.
      The price of $price is right.
      hi there
      The time is Thu 18 Aug 2022 11:12:50 AM CST

      注:Here文档的"<<"右边的标记符用来标记一段文字,可以将遇到下一个相同标记符之前的所有按指定格式存储的内容赋值给"<<"左边的变量,如果左边是print就直接打印右边的内容.例如:
        $a=<< "MARK" #下一行开始,直到遇见"MARK"为止,所有的字符都按照指定的格式存入变量a中.注意perl中定义标量类型(数字,字符串,浮点数)的变量要加$,和shell引用时才加$有区别.

posted on   Mju_halcyon  阅读(16)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示