Created
October 17, 2012 05:46
-
-
Save davfre/3903894 to your computer and use it in GitHub Desktop.
Applied Programming course examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Template for Applied Programming course exercise Day2 Exercise 1 | |
use strict; | |
use warnings; | |
my @sampleA = (65,69,70,63,70,68); | |
my @sampleB = (102,95,98,110); | |
my @sampleC = (112,115,113,109,95,98,100); | |
run_analysis("sampleA",@sampleA); | |
run_analysis("sampleB",@sampleB); | |
run_analysis("sampleC",@sampleC); | |
=head1 run_analysis() | |
Purpose: execute calculations and print report | |
In: string, array of numerical values | |
Out: print to screen | |
=cut | |
sub run_analysis { | |
my ($name,@values) = @_; | |
my $sample_count = scalar(@values); | |
my $avg = calc_avg(@values); | |
my $variance = calc_variance($avg,@values); | |
my $sd = calc_sd($variance); | |
write_report($name,$sample_count,$avg,$variance,$sd); | |
} | |
=head1 write_report() | |
Purpose: print formatted results to screen | |
In: a list of strings | |
Out: print to screen | |
=cut | |
sub write_report { | |
my($tissue,$sample_count,$avg,$variance,$sd) = @_; | |
print "\n"; | |
print "$tissue\n-----\n"; | |
printf "n:%3u\n",$sample_count; | |
printf "average: %5.1f\n", $avg; | |
#... insert printf stateents for variance and sd | |
} | |
=head1 calc_avg() | |
Purpose: calculate the mean of a set of numbers | |
In: an array of numbers | |
Out: scalar | |
=cut | |
sub calc_avg { | |
my (@values) = @_; | |
my $nr_values = scalar(@values); | |
# ... calculate mean | |
return $avg; | |
} | |
sub calc_variance { | |
#code to calculate variance | |
} | |
sub calc_sd { | |
#code to calculate sd | |
# | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment