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)