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
-
输出: 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引用时才加$有区别.
-
- 变量
- 标量$xxx
- 数组@xxx
- 哈希结构%xxx
- 运算符
- 特殊运算符:连接符".";范围符".."
- 子程序
- 传入子程序的参数是一个名为"@_"的数组
- 返回多个数组或哈希表时要用引用的方式
- 参考资料
用代码改变世界!就是这样,喵!
posted on 2022-08-18 11:11 Mju_halcyon 阅读(15) 评论(0) 编辑 收藏 举报