
perl
娜然
横推八百无对手,轩辕重出武圣人
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
perl的hello world
[root@mysql1 perl]# cat 1.pl#!/usr/bin/env perlprint "hello world!\n";print "hello world";[root@mysql1 perl]# cat 2.pl#!/usr/bin/env perluse 5.010;say "hello world!";原创 2016-10-10 11:41:00 · 355 阅读 · 0 评论 -
任意个参数的子程序
[root@mysql1 perl]# cat 19.pl #!/usr/bin/env perluse warnings FATAL => 'all';sub max { my($max_so_far)=shift @_; foreach (@_) { if ($_ > $max_so_far) { $max_so_far=$_;原创 2016-10-12 15:46:37 · 394 阅读 · 0 评论 -
子程序中的return
[root@mysql1 perl]# cat 21.pl #!/usr/bin/env perluse strict;use warnings FATAL => 'all';sub which_element_is { foreach(@_) { print $_,"\n"; } my($what,@array)=@_;原创 2016-10-12 17:29:21 · 1110 阅读 · 0 评论 -
持久性私有变量
[root@mysql1 perl]# cat 23.pl #!/usr/bin/env perluse strict;use warnings FATAL => 'all';use 5.010;sub marine { my $n += 1; print "hello, sailor number $n!\n";}sub marin原创 2016-10-13 14:30:55 · 545 阅读 · 0 评论 -
一个求和函数
[root@mysql1 perl]# cat 25.pl #!/usr/bin/env perluse strict;use warnings FATAL => 'all';sub total { my $sum; foreach (@_) { $sum+=$_; } $sum;}print "the number原创 2016-10-13 15:05:50 · 683 阅读 · 0 评论 -
一个签到函数
[root@mysql1 perl]# cat 27.pl #!/usr/bin/env perluse strict;use warnings FATAL => 'all';use 5.010;sub greet { state $last_person; my $name=shift; print "hi $name! ";原创 2016-10-13 15:44:40 · 1097 阅读 · 0 评论 -
perl读取文件内容
[root@mysql1 perl]# cat test.pl #!/usr/bin/env perlwhile (defined($line= chomp($line); print "it was $line that i saw!\n";}[root@mysql1 perl]# ./test.pl a原创 2016-10-17 14:27:37 · 2200 阅读 · 0 评论 -
printf格式化输出
[root@mysql1 perl]# cat test1.pl #!/usr/bin/env perluse strict;use warnings;my $user='gw';my $days_to_die=36500;printf "hello, %s; your password expires in %d days!\n", $user,$da原创 2016-10-17 15:56:07 · 498 阅读 · 0 评论 -
printf输出数组的内容
[root@mysql1 perl]# cat 28.pl #!/usr/bin/env perluse strict;use warnings FATAL => 'all';my @items=qw( wilma dino pebbles );my $format="the items are:\n".("%10s\n" x @items);pri原创 2016-10-17 16:27:01 · 8973 阅读 · 0 评论 -
perl中的die语法
if ( ! open LOG, '>>', 'logfile' ) { die "cannot create logfile: $!";}如果open失败,die会终止程序的运行,并且告诉我们无法创建日志文件$!:会给我们一个解释,如:fine not found之类的,也就是在c或其他语言里面调用perror取得的字符串。 这个解释性的系统错误信息保原创 2016-11-08 17:29:06 · 11275 阅读 · 0 评论 -
子程序中的私有变量
[root@mysql1 perl]# cat 18.pl #!/usr/bin/env perl#use warnings FATAL => 'all';sub max {# my($m,$n);# ($m,$n)=@_;my($m,$n)=@_; if ($m > $n) { $m } else { $n }原创 2016-10-12 14:46:57 · 466 阅读 · 0 评论 -
子程序的返回值
[root@mysql1 perl]# cat 15.pl #!/usr/bin/env perl#use warnings FATAL => 'all';sub sum_of_fred_and_barney { print "hey, you called the sum_of_fred_and_barney subroutine!\n"; $fred +原创 2016-10-11 18:15:13 · 1608 阅读 · 0 评论 -
翻转数组
[root@mysql1 perl]# cat 5.pl #!/usr/bin/env perlprint "enter some lines, then press ctrl-D:\n"; #或者试试ctrl-Z@lines=;@reverse_lines=reverse @lines;print @reverse_lines;[root@mysql1 perl]原创 2016-10-11 15:19:10 · 281 阅读 · 0 评论 -
数组、输入、sort
[root@mysql1 perl]# cat 8.pl #!/usr/bin/env perlchomp(@lines=);@sorted=sort @lines;print "@sorted\n";[root@mysql1 perl]# [root@mysql1 perl]# [root@mysql1 perl]# ./8.pl caba b原创 2016-10-11 16:26:57 · 293 阅读 · 0 评论 -
变量
[root@mysql1 perl]# ./9.pl the circumference of a circle of radius 12.5 is 78.53981635.[root@mysql1 perl]# cat 9.pl #!/usr/bin/perl -w$pi=3.141592654;$circ=2 * $pi * 12.5;print "the ci原创 2016-10-11 16:42:45 · 307 阅读 · 0 评论 -
变量与输入
[root@mysql1 perl]# ./10.pl what is the radius? 0the circumference of a circle of radius 0 is 0.[root@mysql1 perl]# ./10.pl what is the radius? 1the circumference of a circle of radius 1 is原创 2016-10-11 16:47:49 · 400 阅读 · 0 评论 -
输入变量与if
[root@mysql1 perl]# cat 11.pl #!/usr/bin/perl -w$pi=3.141592654;print "what is the radius? ";chomp($radius=);$circ=2 * $pi * $radius;if($radius$circ=0;}print "the circumference原创 2016-10-11 16:55:21 · 393 阅读 · 0 评论 -
乘法
[root@mysql1 perl]# cat 12.pl #!/usr/bin/env perlprint "enter first number: ";chomp($one=);print "enter second number: ";chomp($two=);$result=$one * $two;print "the result is $result原创 2016-10-11 17:03:50 · 444 阅读 · 0 评论 -
重复字符串
[root@mysql1 perl]# cat 13.pl #!/usr/bin/env perlprint "enter a string: ";$str=;print "enter a number a times: ";chomp($num=);$result=$str x $num;print "the result is:\n$result";pr原创 2016-10-11 17:12:11 · 522 阅读 · 0 评论 -
子程序与变量
[root@mysql1 perl]# cat 14.pl #!/usr/bin/env perlsub marine { $n += 1; # 全局变量$n print "hello, sailor number $n|\n";}sub marine1 { my $n += 1; print "hello, sailor number $原创 2016-10-11 17:35:35 · 585 阅读 · 0 评论 -
usUselesse of addition (+) in void context at ./16.pl line 7.
如果在perl中你定义了一个子程序,并且启用了警告,子程序中的运算结果没有被存储起来,这时候perl会将其丢弃,并且报错:Useless use of addition (+) in void context at来警告你,其中的void context(空的上下文),表示运算结果没有存储到变量里,也未被任何函数使用。例子:[root@mysql1 perl]# cat 16.pl #原创 2016-10-11 18:13:08 · 850 阅读 · 0 评论 -
say
[root@mysql1 perl]# cat 35.pl #!/usr/bin/env perluse strict;use warnings FATAL => 'all';use 5.010;print "hello!\n";print "hello!","\n";say "hello!";[root@mysql1 perl]# [r原创 2016-11-14 15:50:10 · 432 阅读 · 0 评论