Free web development scripts for the webmasterDevelopment Scripts

 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 3 users online
 o Most users online: 67
 o Home
  o Perl
   o Miscellaneous
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o Advertise Here Make Money
 o Open Source Design
 o devnet
 o Free Wedding Websites
 o Wedding Vendor Directory
 o OxyScripts
 o designplace

Find the Median Value of an Array (Rated 0)

Description:

You can use this simple function to find the Median Value of an Array

Code starts here


# median() returns a median value.
# USAGE: median(@array) where @array is
# an array of all values
# to be considered.
#
sub median {
my(@values) = sort(@_);
my($mid) = scalar(@values) >> 1;

# If there is an even number of values
# in @values, then you need to add them
# and divide by two to get the median.

return($values[$mid]) if $mid & 1;

($values[$mid-.5] + $values[$mid+.5]) / 2;
}


Submitted by Devscripts on 24-02-2003 12:06


Rate This Script

User Contributed Comments

Registered Members login
© Copyright 2003 - Devscripts.net