answersLogoWhite

0


Best Answer

<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

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you calculate the average and median in perl by subroutine?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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 Learning Perl created?

Learning Perl was created in 1997.


What is the cat command in perl?

The concatenate operator in perl is a period, ie .


Is PERL an interpreted or compiled programming language?

Perl is both compiled and interpreted language. In the traditional sense, Perl is a pure interpreted language. The reference Perl program is a prototypical two-stage interpreter: when a Perl script is invoked via #!/bin/perl (or similar), the perl interpreter performs a language parsing on the source code, creating an internal (to the perl interpreter) representation of program, which is then translated into binary code for execution. Every invocation of a perl program requires this translation/interpretation to be completed. There are several projects which can take perl source code and compile it down to a binary executable (that is, bypass the whole repeated translate/interpret phase each time). However, these are NOT complete - even the best can only manage about 95% of the perl code available. That is, these perl compiler are incomplete implementations of the Perl language. They can be very useful, but are not complete substitutes for the Perl interpreter. The real answer is that Perl was designed to be an interpreted language from the start; attempts to turn Perl into a compiled language are faced with the difficulty of Perl's sprawling syntax and complete lack of design for compilation, and thus, struggle to implement all the languages features in a compiler.

Related questions

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 Alfredo Perl born?

Alfredo Perl was born in 1965.


When was Gisella Perl born?

Gisella Perl was born in 1907.


When did Gisella Perl die?

Gisella Perl died in 1988.


When was Black Perl created?

Black Perl was created in 1990.


When was Intermediate Perl created?

Intermediate Perl was created in 2003.


When was Hille Perl born?

Hille Perl was born in 1965.


When was Mastering Perl created?

Mastering Perl was created in 2007.


When was Curdin Perl born?

Curdin Perl was born in 1984.


When was Programming Perl created?

Programming Perl was created in 1991.