Perl 语言入门课后习题
发布时间:2020-12-16 00:14:02 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl#use strict;use 5.010;use warnings;use strict;sub total{my $lost;foreach (@_) {$lost+=$_;}$lost;}#my @nnaa=qw/1 2 3 4 5 1 1 2 4 1 2 4/;#print total(1..1000);sub above_average{my $total; foreach (@_) { $total+=$_; } my $avera
#!/usr/bin/perl #use strict; use 5.010; use warnings; use strict; sub total{ my $lost; foreach (@_) { $lost+=$_; } $lost; } #my @nnaa=qw/1 2 3 4 5 1 1 2 4 1 2 4/; #print total(1..1000); sub above_average{ my $total; foreach (@_) { $total+=$_; } my $average=$total/@_; foreach (@_) { if ($_>$average) { print $_," "; } } } #&above_average(1..100); sub greet{ state $num=0; state @allpe; my $name; if ($num==0) { print "Hi ",$_[0],",You are the first one here","n"; push @allpe,$_[0]; $num++; } elsif ($num>0) { print "Hi "," there is "; foreach $name (@allpe) { print $name," "; } print "here","n"; push @allpe,$_[0]; $num++; } } &greet("john"); &greet("li"); &greet("sha");
1、由于环境是activeperl,在使用state标志时,必须先声明use 5.010; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |