一个签到函数

2016-10-13 20:21:11来源:CSDN作者:g13731463274人点击

第七城市
[root@mysql1 perl]# cat 27.pl 
#!/usr/bin/env perl


use strict;
use warnings FATAL => 'all';
use 5.010;


sub greet {


  state $last_person;
  my $name=shift;
  print "hi $name! ";


  if (defined $last_person) {
    print "$last_person is also here!/n";
  } else {
    print "you are the first one here!/n";
  }
  $last_person=$name;



sub greet1 {
  state @names;
  my $name=shift;
  print "hi $name! ";
  
  if (@names) {
    print "i've seen: @names/n";
  } else {
    print "you are the first one here!/n";
  }
  push @names,$name
}


greet('fred');
greet('barney');


greet1('fred');
greet1('barney');
greet1('wilma');
greet1('betty');






















[root@mysql1 perl]# ./27.pl   
hi fred! you are the first one here!
hi barney! fred is also here!
hi fred! you are the first one here!
hi barney! i've seen: fred
hi wilma! i've seen: fred barney
hi betty! i've seen: fred barney wilma
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台