Skip to content

hlmarkc/median.pl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

median.pl

#!usr/bin/perl -w

#first to identify if there is a list or a file if (-e $ARGV[0]){ @a=(); open (IN, "<$ARGV[0]"); while (){ chomp($); push (@a, $); } close IN; } else { @a = @ARGV; }

#make the data after re-arrangement (from small value to large) to be a new list @sa = sort {$a <=> $b} @a;

print "@sa\n";

#identify the median between even or odd-ordered lists if (($#sa+1)%2 == 0){ $median = ( $sa[($#sa+1)/2-1] + $sa[($#sa+1)/2] )/2; }

else {
   $median = $sa[$#sa/2];

}

print "The median is $median. \n";

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published