#!/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 ",$_[0]," 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;