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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.