首页 / PERL / perl小程序(一)
perl小程序(一)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了perl小程序(一),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1788字,纯文字阅读大概需要3分钟。
内容图文
1 请用perl在屏幕输出hello,world
[root@localhost perl]# cat perlhello.pl #!/usr/bin/perl print "hello,world!\n"; [root@localhost perl]# ./perlhello.pl hello,world!
2 截取出正则的匹配内容,在shell中,真是头都大了
#!/usr/bin/perl -w $_="<span class=\"title\">Counter-Strike Global Ofensive</span>"; if(/<span class=\"title\">(.*)<\/span>/) { print "$1\n"; }
[root@localhost perl]# ./perlre.pl Counter-Strike Global Ofensive
稍微改动下,截取括号的内容,也是很简单
#!/usr/bin/perl -w
#注意每一句以分号结尾,注意是否转义
$_="(Counter-Strike Global Ofensive)"; if(/\((.*)\)/) { print "$1\n"; }
3 接受标准输入,并输出
#!/usr/bin/perl -w while (<>) {print;}
[root@localhost perl]# ./receive.pl
hello,i am liuliancao
hello,i am liuliancao
4 计算圆的面积
#!/usr/bin/perl -w print "please input the radius of the circle"; $r=<STDIN>; if($r lt 0) {$c=0;} else {$c=2*$r*3.141592654;} print "the c is $c\n";
[root@localhost perl]# ./circle.pl please input the radius of the circle:1 the c is 6.283185308
5 计算两个数的乘积,并输出它们
#!/usr/bin/perl -w print "please input two number divided by Enter,and i will mutiply them\n"; chomp($a=<STDIN>); $b=<STDIN>; print "a is $a, and b is $b and the muti result is ",$a*$b," !\n";
[root@localhost perl]# ./muti.pl
please input two number divided by Enter,and i will mutiply them
2
5
a is 2, and b is 5
and the muti result is 10 !
6 重复输出指定次数字符串
#!/usr/bin/perl -w print "please input string and times divided by Enter!\n"; chomp ($a=<STDIN>); $b=<STDIN>; $result=$a x $b; print "result is $result\n";
[root@localhost perl]# ./stringtimes.pl please input string and times divided by Enter! liuliancao 5 result is liuliancaoliuliancaoliuliancaoliuliancaoliuliancao
本文出自 “启学的学习之路” 博客,请务必保留此出处http://qixue.blog.51cto.com/7213178/1659264
原文:http://qixue.blog.51cto.com/7213178/1659264
内容总结
以上是互联网集市为您收集整理的perl小程序(一)全部内容,希望文章能够帮你解决perl小程序(一)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。