Guide Practice of Perl
来源:互联网 发布:黑暗网络进入方法 编辑:程序博客网 时间:2024/05/21 10:51
#!/usr/bin/perluse strict;use warnings;#This is a practice of perl, as which shows with below perl code...codes.print "Hello, world!\n";my $animal = "camel\n";my $answer = 42;printf $animal;print "The animal is $animal\n";print "The square of $answer is ", $answer * $answer, "\n";print;my @test = ("t1", "t4", "t3");print $test[0], $test[1], $test[$#test], "\n";print "@test\n";my @sorted = sort @test;print "@sorted\n";my @backwards = reverse @test;print "@backwards\n";my %fcolor = ( apple => "red", banana => "yellow",);my $apple = $fcolor{"apple"};print "apple color is $apple. \n";my @fruits = keys %fcolor;my @colors = values %fcolor;print "list fruits: @fruits. \n";print "list colors: @colors. \n";my $variables = { scalar => { desc => "sigle item", sigil => '$', }, array => { desc => "ordered list of items", sigil => '@', }, hash => { desc => "key/value pairs", sigil => '%', }, };print "scalar begin with a $variables->{'scalar'}->{'sigil'}. \n";print "array begin with a $variables->{'array'}->{'sigil'}. \n";print "hash begin with a $variables->{'hash'}->{'sigil'}. \n";my $x = "x";my $some_condition = 1;if ($some_condition) { my $y = "y"; print $x; print $y;}print $x;#print $y;print "\n";print "unless condition.\n" unless(0);until (1) { print "while condition.\n";};foreach (@test) { print "array element is $_\n";}print "array element is $test[$_]\n" foreach 0 .. $#test;foreach my $key (keys %fcolor) { print "The value of $key is $fcolor{$key} \n";}my $a = 1;$a += 1;print "$a\n";$a -= 1;print "$a\n";$a .= "x";print "$a\n";open(my $in, "<", "input.txt") or die "can't open input.txt: $!\n";#my $line = <$in>;#my @lines = <$in>;#print "$line";#print "@lines";print stderr "stderr test.\n";while (<$in>) { print "$_";}print "\n";close $in or die "$in: $!";open(my $out, ">", "output.txt") or die "can not open output.txt. \n";print $out "hello world!\nWrite this info into output.txt. \n";close $out or die "$out: $!";=podwhile(<>) { next if /^$/; last if (/q/); print;}=cutmy $email = "hk.mars\@aol.com";if ($email =~ /([^@]+)@(.+)/) { print "username is $1 \n"; print "hostname is $2 \n";}#subroutinessub loger { my $logmessage = shift; open my $logfile, ">>", "my.log" or die "can not open my.log.$!"; print $logfile $logmessage;}loger("hello loger! \n");sub square { my $num = shift; my $sq; $sq = $num * $num; return $sq;}my $sq = square(5);print "the square result of 5 is $sq \n";#OO Perl#Using Perl modules#The end of this practice, let's start to write project...now...Write above perl codes into "e1.pl" file or any name as you want, and executes it on the shell, below is the result shown:
Yeah, perl is so easy as C. I am so expected to start the web project using perl. I guess only need one week to hack a website done.
Mars
0 0
- Guide Practice of Perl
- perl practice
- FIRST Best Practice Guide Library
- The practice of programming
- Do Lots of Deliberate Practice
- <<The Practice of Programming>>序言
- Do Lots of Deliberate Practice
- Practice of using spinlock instead of mutex
- note of Perl (一)
- note of Perl (二)
- note of Perl (三)
- note of Perl (四)
- ”The Importance of Perl “
- HTML Dog: The Best-Practice Guide to XHTML and CSS
- Penetration Testing Skills Practice with Metasploitable (Beginner Guide)
- User's Guide Of Dagger2
- 读书摘要-The practice of programming
- Practice of System and Network Administration
- ant 编译 aidl 报告错误: couldn't find import for class
- js获取html中的table元素里的每一行的行号
- PAT 1009. 说反话
- Android 使用Log4j把日志写入SD卡,动态修改输出文件名称
- 判断是否为闰年
- Guide Practice of Perl
- linux expect的用法
- 向左轮播滑动
- Codeforces Round #295 (Div. 2) A+B+C
- IOS学习初期的一些学渣感受[参考意义在于学习的顺序过程]
- 大数相乘
- C++虚函数
- 使用C++实现一套简单的状态机模型——实例
- 关于struct,enum和typedef的知识总结