answersLogoWhite

0

<pre>

sub average {

@_ 1 or die ('Sub usage: $median = median(\@array);');

my ($array_ref) = @_;

my $count = scalar @$array_ref;

# Sort a COPY of the array, leaving the original untouched

my @array = sort { $a <=> $b } @$array_ref;

if ($count % 2) {

return $array[int($count/2)];

} else {

return ($array[$count/2] + $array[$count/2 - 1]) / 2;

}

}

</pre>

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

Can you assign your scope to subroutione in perl ex like this my sub fun name....definition of function...?

Yes, in Perl, you can assign a scope to a subroutine using the my keyword to declare variables within the subroutine, allowing them to be scoped locally to that subroutine. For example: sub fun { my $local_var = &quot;I'm local&quot;; # This variable is scoped to the subroutine print $local_var; } This keeps $local_var from being accessible outside of fun, ensuring encapsulation within the subroutine.


Can you merge c and perl?

Yes, C and Perl can be made to talk together quite well. XS (http://en.wikipedia.org/wiki/XS_(Perl)) is the most widely used method for doing this - it allows you to write binding to C or C++ code so it can be called as a perl subroutine. Inline::C (http://search.cpan.org/~ingy/Inline-0.44/C/C.pod) is another method - it allows you to write C code inside Perl code and generates the necessary XS automatically. If you want to call perl code from C, you can link against libperl.


What are some facts about Perl?

Perl is a programming language. Perl is an interpreted programming language. Perl is very useful for shell scripts, application programming, and web applications. Perl is quite easy to learn. Perl can be, but does not have to be, object-oriented. Perl was created by Larry Wall. Perl has probably the best implementation of regular expressions in existence.


Where can one find information about Learning Perl?

There are a number of sites that provide information about how to learn the Perl programming language. They include Learn Perl, Learning Perl and Perl Tutorial Hub. Amazon and other good booksellers have a wide range of Perl books available.


When was Gisella Perl born?

Gisella Perl was born in 1907.


When did Gisella Perl die?

Gisella Perl died in 1988.


When was Curdin Perl born?

Curdin Perl was born in 1984.


When was Alfredo Perl born?

Alfredo Perl was born in 1965.


When was Black Perl created?

Black Perl was created in 1990.


When was Programming Perl created?

Programming Perl was created in 1991.


When was Intermediate Perl created?

Intermediate Perl was created in 2003.


When was Learning Perl created?

Learning Perl was created in 1997.