<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><p><anchor-end xmlns="urn:x-suika-fam-cx:markup:suikawiki:0:9:" a0:anchor="1" xmlns:a0="urn:x-suika-fam-cx:markup:suikawiki:0:9:">[1]</anchor-end> <pre class="perl example code">
sub get_total_of (@) {
  my $sum = 0;
  for (@_) {
    $sum += $_;
  }
  return $sum;
}

sub get_mean_of (@) {
  return get_total_of (@_) / (scalar @_ or 1);
}

sub get_variance_of (@) {
  my $mean = get_mean_of (@_);
  return get_mean_of (map { ($_ - $mean) ** 2 } @_);
}

sub get_confidence_interval_of ($@) {
  my $percentage = shift;
  my $z = {
    90 =&gt; 1.645, 95 =&gt; 1.960, 99 =&gt; 2.576, 99.9 =&gt; 3.29,
  }-&gt;{$percentage};
  return undef unless defined $z;
  my $stddev = sqrt (get_variance_of (@_));
  my $n = @_ || 1;
  return $z * $stddev / sqrt $n;
} # get_confidence_interval_of</pre></p></body></html>