标签:
Perl中有三种内置的变量类型:
类型 | 语法 | 示例 |
整型 | NN | 89 |
浮点型 | NN.NN | 12.34 |
科学计数 | NN.NNeNN | 23.04e-5 |
大数 | NN_NNN_NNN | 19_000_000 |
八进制 | 0NNN | 0761 |
十六进制 | 0xNNNN | 0xF9DA |
转义字符 | 意义描述 |
\a | 响铃 |
\b | 退格 |
\cn | Ctrl+n 做控制字符 |
\e | ESC(ASCII编码的转义字符) |
\f | 跳页 |
\n | 换行 |
\t | 制表符 |
\r | 回车 |
\l | 将下个字符转为小写 |
\L | 将到 \E 为止的所有字符转为小写 |
\u | 将下个字符转为大写 |
\U | 将到 \E 为止的所有字符转为大写 |
\Q | 将到 \E 位置的非单词字符加上反斜线 |
\E | 结束\L 、\U、 \Q |
\007 | 任何八进制的ASCII(此处表示系统响铃) |
#!/usr/bin/perl $animal = "camel"; $answer = 42; print $animal; print "The animal is $animal\n"; print "The square of $answer is", $answer * $answer ,"\n";
#!/usr/bin/perl @animaals = ("camel", "llama", "owl"); @animaals_1 = qw(camel llama owl); @numbers = (1,2,3); @numbers_1 = (1..3); @mixed = ("camel",42,1.23); print "@animaals\n@animaals_1\n@numbers\n@numbers_1\n@mixed\n"; print "$animaals[0] $animaals[1] $animaals[2]\n"; print "@animaals[0,1]","\n"; print "@animaals[0..1]\n"; print "@animaals[0..$numbers[0]]\n";
直接以数组的形式一次给出散列中的键和值 %map = ('red',0xff0000,'green',0x00ff00,'blue',0x0000ff); 以大括号的形式分别给出键和值 %map = (); ##清空这个哈希变量 $map{red} = 0xff0000; $map{green} = 0x00ff00; $map{blue} = 0x0000ff; 用”=>“ 符号依次给出键和值对 %map = (); %map = ( red => 0xff0000, green => 0x00ff00, blue => 0x0000ff );
标签:
原文地址:http://blog.csdn.net/u011641885/article/details/45974471