Perl applet (i)

Source: Internet
Author: User

1 Please use Perl on the screen output Hello,world

[email protected] perl]# cat perlhello.pl #!/usr/bin/perlprint "hello,world!\n"; [Email protected] perl]#/perlhello.pl hello,world!

2 intercept regular matches, and in the shell, it's a big head.

#!/usr/bin/perl-w$_= "<span class=\" title\ ">counter-strike Global ofensive</span>"; if (/<span class=\ "Title\" > (. *) <\/span>/) {print "$1\n";}
[Email protected] perl]#/perlre.pl Counter-Strike Global ofensive

A little change, the interception of the contents of the parentheses is also very simple

#!/usr/bin/perl-w

#注意每一句以分号结尾, notice whether escaping

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

3 Accept the standard input and output

#!/usr/bin/perl-wwhile (<>) {print;}

[Email protected] perl]#./receive.pl

Hello,i am Liuliancao

Hello,i am Liuliancao

4 Calculating the area of a circle

#!/usr/bin/perl-wprint "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";
[Email protected] perl]#/circle.pl Please input the radius of the circle:1 the C is 6.283185308

5 calculates the product of two numbers and outputs them

#!/usr/bin/perl-wprint "Please input II divided by Enter,and I'll mutiply them\n"; Chomp ($a =<stdin>); $b =&L T Stdin>;p rint "A is $a, and B are $b and the muti result is", $a * $b, "!\n";

[Email protected] perl]#./muti.pl

Please input the number divided by Enter,and I'll mutiply them

2

5

A is 2, and B is 5

And the muti result is 10!

6 repeating output specified number of times string

#!/usr/bin/perl-wprint "Please input string and times divided by enter!\n"; Chomp ($a =<stdin>); $b =<stdin>;$ result= $a x $b;p rint "result is $result \ n";
[Email protected] perl]#./stringtimes.pl please input string and times divided by Enter!liuliancao5result Iuliancaoliuliancaoliuliancaoliuliancao




This article is from the "Learning Path of Kai Learning" blog, please make sure to keep this source http://qixue.blog.51cto.com/7213178/1659264

Perl applet (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.