Yes, I have already found a way to get mode for the set of numbers in a couple of ways.
my ($mode_num)=alt_mode_num(@data); print "Mode : $mode_num\n"; sub alt_mode_num{ my %count=(); for (sort{$a <=> $b} @_){ $count{$_}++; } my @key= sort{$count{$b}<=>$count{$a}} keys %count; #print " Key with highest value is $keys[0] \n"; return $key[0]; }
BUT I saw this way of passing the values by ref in this forum and wanted to duplicated it but failed
this is the model I used to try to get my mode sub to look like
my @num =(1..10); my @words = qw(hello world inside); function( {NUMBERS=>\@num, WORDS=>\@words} ); exit; sub function { die "no parameter!\n" unless @_; my %opt = %{ shift @_ }; my @i_words = $opt{WORDS}; print "this r words", Dumper \@i_words; my @i_numbers = $opt{NUMBERS}; print Dumper \@i_numbers; }
(one of my problemS) is getting a counter and a compare for highest value.
I specifically wanted this so I can see how it is done properly when using this way
In reply to Re^2: Help fixing this piece of code
by perlynewby
in thread Help fixing this piece of code
by perlynewby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |