加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl小程序(一)

发布时间:2020-12-15 23:43:43 所属栏目:大数据 来源:网络整理
导读:?1 ?请用perl在屏幕输出hello,world [root@localhost?perl]#?cat?perlhello.pl?#!/usr/bin/perlprint?"hello,world!n";[root@localhost?perl]#?./perlhello.pl?hello,world! 2 ?截取出正则的匹配内容,在shell中,真是头都大了 #!/usr/bin/perl?-w$_="span?

?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?"$1n";
}
[root@localhost?perl]#?./perlre.pl?
Counter-Strike?Global?Ofensive

稍微改动下,截取括号的内容,也是很简单

#!/usr/bin/perl -w?

#注意每一句以分号结尾,注意是否转义

$_="(Counter-Strike?Global?Ofensive)";
if(/((.*))/)
{
print?"$1n";
}

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?$cn";
[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?themn";
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?$resultn";
[root@localhost?perl]#?./stringtimes.pl?
please?input?string?and?times?divided?by?Enter!
liuliancao
5
result?is?liuliancaoliuliancaoliuliancaoliuliancaoliuliancao

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读