#Example1 #while循环
#!/usr/bin/perl
use 2.010; #声明本校本所使用的版本号
while(<>){ #接收键盘的任意输入
chomp;
print join(" ",(split /:/)), "
"; 首先用':'分隔字符串,然后用' '(制表符)连接
}
#Example2 #函数
#!/usr/bin/perl
@lines = `perldoc -u -f atan2`;
foreach (@lines) {
s/w<([^>]+)>/U$1/g;
print;
}
#Example3 #真正的第一个可以运行的东东,只输出一句话
#!/usr/bin/perl
printf ("%s","hello"." "."word
"); #格式控制(%s)只对printf有效
print ("%s","hello"." "."word
"); #格式控制(%s)被当做字符输出
print "hello word!
"; #括号可以删除掉的
print "hello word!
"; #空格和叹号的转义也可以删掉
print ("%s","hello"," ","word
"); #下面四个的输出完全一样
print ("%s"."hello"." "."word
");
print "%s","hello"," ","word
";
print "%s"."hello"." "."word
";
say "%s"."hello"." "."word
"; #这个也是输出一句话,不过要求版本最低是5.010
#Example4 #接收输入参数
#!/usr/bin/perl
$line = <STDIN>;
if ($line eq "
"){ #如果只有一个回车
print "That was just a blank line!
";
} else {
print "That line of input was: $line";
}
#Example5 #见识一下perl里的赋值操作
#!/usr/bin/perl
print "5" x 4; #输出4个5
print "
"; #输出一个回车
print "yu_qq" x (4+1); #输出( 4+1)=5遍的yu_qq
print "
";
$lin = "abc" ;
$ll = "f";
$lin .= "d"; #'.'连接字符串,和JAVA中的'+'相同,把d加到$lin(abc)后面
$lin = $ll . $lin; #把两个($ll和$lin)连在一块儿
print "$lin";
print "
";
$num= "5" x 4;
print "$num
";
$num -= 5500; #双目操作运算,连在一起简写了
print "$num
";
$num *= $num;
print "$num
";