Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am not sure whether i need to print values as well as return them? (not really sure exactly what return does) also how do i return to an OUTFILE with return. If anyone has any better solutions to this problem they will be much appreciated.#! /usr/local/bin/perl -w use strict; my $num_of_params; $num_of_params = @ARGV; if ($num_of_params < 2) { die ("\n You haven't entered enough parameters \n"); } open (BLASTX, $ARGV[0]) or die "unable to open file"; open (OUTFILE, ">$ARGV[1]"); my $line; my @array; my $number; my $count=0; my @frequency; my %count; my @ordered; while (<FILE>) { $line = $_; chomp ($line); @array = (); @array = split (/\s+/, $line); @frequency = $array[0]; sub odd_median { @frequency = shift; @array = sort @frequency; return $array[(@array - (0,0,1,0) [@array & 3]) /2]; } sub mode { @frequency = shift; my (%count, @result); foreach (@frequency) { $count{$_}++; } foreach (sort { $count{$b} <=> $count{$a} } keys %count) { last if @result && $count{$_} != $count{$result[0]}; push (@result, $_); } return odd_median \@result; } } close OUTFILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: calculating the mode
by frankus (Priest) on Jun 10, 2002 at 09:37 UTC | |
by Anonymous Monk on Jun 10, 2002 at 10:23 UTC | |
by frankus (Priest) on Jun 10, 2002 at 10:48 UTC | |
|
Re: calculating the mode
by Bilbo (Pilgrim) on Jun 10, 2002 at 11:20 UTC | |
by particle (Vicar) on Jun 10, 2002 at 12:09 UTC | |
by demerphq (Chancellor) on Jun 13, 2002 at 12:56 UTC | |
by Anonymous Monk on Jun 10, 2002 at 12:06 UTC | |
|
Re: calculating the mode
by zejames (Hermit) on Jun 10, 2002 at 09:45 UTC | |
|
Re: calculating the mode
by perigeeV (Hermit) on Jun 10, 2002 at 10:57 UTC |