You really need to start learning to use the debugging tools you've chosen -- in thise case, Data::Dump.

I wrote my own data dumper so I apologize for using a nonstandard module here to demonstrate, but it gets the point across quite nicely. I made the following changes:

sub median_num{ my @sorted= @_; #using shift didn't work, why? format? &debug::debugdumplist("median_num(): \@sorted", \@sorted);

Notice in the results how median_num()receives two different types of structures:

D:\PerlMonks>shift3.pl Using a hash as a reference is deprecated at D:\PerlMonks\shift3.pl li +ne 54. median_num(): @sorted (S:/Steve/Perl/debug.pm:887): [ARRAY(0x2ae0c28)] [1] [1] [2] [3] [3] [3] [3] [4] [5] [7] [8] [12] [12] [23] [25] [32] [33] [42] [43] [43] [44] [55] mean : 18.3636363636364 length : 22 median_num(): @sorted (S:/Steve/Perl/debug.pm:887): [1] [1] [2] [3] [3] [3] [3] [4] [5] [7] [8] [12] [12] [23] [25] [32] [33] [42] [43] [43] [44] [55] this is median : 12 this will be middle num position : 11.5 this is length :22 Use of uninitialized value in concatenation (.) or string at D:\PerlMo +nks\shift3.pl line 29. 1 1 2 3 3 3 3 4 5 7 8 12 12 23 25 32 33 42 43 43 44 55 D:\PerlMonks>

Look closely at the first one; the @sortedarray contains another ARRAY; and that array then has scalar values in it. This is an array of arrays.

Look at the second one; no embedded ARRAY; @sortedsimply contains scalar values.

So I looked at the lines in your code which call median_num(), and lo and behold, you are not using the subroutine consistently:

my ($middle,$median)=median_num(@new_sort); median_num(\@sorted);

The first line calls median_num()with an array as its parameter list.

The second one calls it with a REFERENCE to an array. In Cterms, you've passed it by reference instead of by value

Betting this inconsistency has something to do with why shiftdidn't work.

Also, you might want to clean up your errors and warnings, but you probably knew that.


In reply to Re: unxpected sort warnings while using sort by marinersk
in thread 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.