Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use IO::File;
- my @floats;
- while (my $text = <STDIN>) {
- chomp($text);
- push(@floats, $text);
- last if ($text eq '');
- }
- pop(@floats);
- my $median = median(@floats);
- my $medianfileh = new IO::File(">./median.txt");
- print $median $medianfileh;
- undef $medianfileh;
- sub median{
- my @a = sort {$a <=> $b} @_;
- return ($a[$#a/2] + $a[@a/2]) / 2;
- }
Add Comment
Please, Sign In to add comment