子程序的返回值

2016-10-11 19:54:33来源:CSDN作者:g13731463274人点击

[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 + $barney;  
}


sub sum_of_barney_and_fred {
  print "hey, you called the sum_of_barney_and_fred subroutine!/n";
  $fred + $barney;   
  print "hey, i'm returning a value now!/n";  
}


$fred = 3;
$barney = 4;
$wilma = &sum_of_fred_and_barney;
print "/$wilma is $wilma./n";


$betty = 3 * &sum_of_fred_and_barney;
print "/$betty is $betty./n";


$wilma = &sum_of_barney_and_fred;
print "/$wilma is $wilma./n";


$betty = 3 * &sum_of_barney_and_fred;
print "/$betty is $betty./n";
[root@mysql1 perl]# 
[root@mysql1 perl]# 
[root@mysql1 perl]# 
[root@mysql1 perl]# ./15.pl   
hey, you called the sum_of_fred_and_barney subroutine!
$wilma is 7.
hey, you called the sum_of_fred_and_barney subroutine!
$betty is 21.
hey, you called the sum_of_barney_and_fred subroutine!
hey, i'm returning a value now!
$wilma is 1.
hey, you called the sum_of_barney_and_fred subroutine!
hey, i'm returning a value now!
$betty is 3.

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台