|
perl的简单转义列表:
\n 换行
\r 回车
\t 制表符
\b 退格
\u 将下一个字符改为大写
\i 将下一个字符改为小写
\\ 直接量反斜杠字符
\' 用单引号('')括起来的字符串中的直接量'
\" 用引号括起来的字符串中的直接量"
qq 相当于双引号 q相当于单引号实例如下:
print qq(I said "Go then," and he said "I'm gone" \n);
print q(Jesse's and tom's);
界限符:<>(){}//......
标量:
变量名:a-z A-Z 数字或下划线_ 但是首字符不能使数字
变量区分大小写
标量变量使用的时候 不必进行声明或者初始化 如果使用数字 perl默认值为0
如果使用别的字符串 其默认值为" " 即空值.
特殊变量:
$_ 默认值
$_ = "what a country pao!";
print ;
#/usr/bin/perl -w 指的是perl的开关告诉perl遇到警告就通知你;
字符运算符: .表示连接
$a="mei qi";
$b="lu ya";
$c=$a . $b
重复字符串:x print "_" x 90;
带名字的运算符:
int(1.34)=1
length(meiqi)=5
lc("HELLO")=hello 转换成小写字母
uc(hello)=HELLO 返回和lc相反的结果
cos(50) 返回弧度50的余玄角
rand(5) 返回0到该数值之间的一个随机数
<>运算符 标准输入:
#!usr/bin/perl
print "What size is your shoe? ";
$size=<STDIN>;
print "Your shoe size is $size,Thank you";
[iyunv@CHN-YX-1-01 perl]# cat hello.pl
#!usr/bin/perl
print "What size is your shoe? ";
$size=<STDIN>;
chomp $size; #chomp删除任何结尾处的任何换行符 它返回被删除的字符数1 但是如果没有字符删除 默认为0
print "Your shoe size is $size,Thank you";
递增和递减:
$counter=$counter + 1;
print $counter;
$counter=100;
$counter++;
print $counter;
#!/usr/bin/perl
$counter=100;
$counter--;
print $counter;
赋值追加运算符实例:
[iyunv@80sa test]# cat test.pl
#!/usr/bin/perl
$line="hello world";
$line.=",at the end";
print $line;
[iyunv@80sa test]# perl test.pl
hello world,at the end
#same as $y=$y*$x
$y*=$x;
print $y;
$r%=67;
print $r;
学习利息小实例:
[iyunv@80sa test]# cat test.pl
#!/usr/bin/perl
print "Monthly deposit amount?";
$pmt=<STDIN>;
chomp $pmt;
print "Annual Interest rate? (ex. 7% is .0.7) ";
$interest=<STDIN>;
chomp $interest;
print "Number of months to deposit?";
$mons=<STDIN>;
chomp $mons;
$interest/=12;
$total=$pmt * (( 1 + $interest) ** $mons -1 )/ $interest;
print "After $mons months,at $interest monthly you \n";
print "will have $total .\n"; |
|
|