hello monks

Ok, I fixed most of my problems

but I found another instance where my @sorted= shift@_ didn't work. it worked with @_ only

my @sorted= @_; #using shift didn't work, why? format?

trying to read about it to find solution/explanation but no luck yet

Anyhow, still looking to create an algorithms to find the element that appears the most and return it

not too much luck so far but working on this still

Monks , I am updating the previous post coz yesterday I was to frustrated not finding solutions to my issues

still trying to find how to properly use/pass a var=value from inside one sub into another sub

this is the code I fix

use strict; use warnings; use autodie; use Data::Dump qw(dump); open my $in, '<', 'numbers.txt' or die $!; my @data =split/\s+/,<$in>; close $in; my ($mean,$ref,@new_sort)= sort_num(@data); my $length=$$ref; #passing by ref example #print "sorted : @new_sort\n"; print "mean : $mean\n"; print "length : $length\n"; my ($middle,$median)=median_num(@new_sort); print "this is median : $median\n"; print "this will be middle num position : $middle\n"; my ($size,$hash_ref)=mode_num( {NUMBERS=>\@new_sort} ); # my $true_size=$$size; print "this is length :$true_size\n"; foreach my $k (keys %$hash_ref){ for (0..$length){ print " $hash_ref->{$k}[$_]"; #%hash->NUMBER=> i_number #there are + undef but dump doesn't show these } } # my sub practice with ref and hash_ref sub sort_num{ our @sorted=sort {$a <=> $b}@_; our $length = scalar (@sorted); our $add_div_elem =(eval join '+',@sorted)/$length; median_num(\@sorted); return $add_div_elem,\$length,@sorted; } sub median_num{ my @sorted= @_; #using shift didn't work, why? format? my $middle_one = eval ((scalar @sorted)+ 1)/2; my $median=$sorted[$middle_one]; return ( $middle_one, $median)# } #passing by references sub mode_num{ my %opt = %{shift @_ } ; #creating hash my $size=keys %opt->{NUMBERS}; #getting size of hash #my %count=(); #for (0..$size){ #have to defined the hash coz perl will see 0 if undef # foreach my $key ( keys %opt->{$key}){ # my $value= $opt->{$key}[$_]; # if (not exists $count{$value}){ # $count{$value}=[]; # } # push $count{$value},$key; # } #} return \$size,\%opt; }

In reply to unxpected sort warnings while using sort 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.