Guest User

Untitled

a guest
Dec 10th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use IO::File;
  3.  
  4. my @floats;
  5.  
  6. while (my $text = <STDIN>) {
  7. chomp($text);
  8. push(@floats, $text);
  9. last if ($text eq '');
  10. }
  11.  
  12. pop(@floats);
  13. my $median = median(@floats);
  14. my $medianfileh = new IO::File(">./median.txt");
  15. print $median $medianfileh;
  16. undef $medianfileh;
  17.  
  18. sub median{
  19. my @a = sort {$a <=> $b} @_;
  20. return ($a[$#a/2] + $a[@a/2]) / 2;
  21. }
Add Comment
Please, Sign In to add comment