徐小玉的博客。
分类: PERL
2019-11-01 11:37:39
#!/usr/bin/perl
package average; # Declare a package
# Average a list of grades
sub ave {
my(@grades)=@_;
my($num_of_grades)=$#grades + 1;
foreach $grade ( @grades ){
$total += $grade;
}
$total/$num_of_grades; # What gets returned
}
1; # Make sure the file returns true or require will not succeed!
#!/usr/bin/perl
unshift(@INC, "/Users/mc/codes/perl/mylib");
require "average.pl";
print "Enter your midterm scores.\n";
@scores=split(' ',
printf "The average is %.1f.\n", average::ave(@scores);
# The ave subroutine is found in a file called average.pl