There's more than one way to do things | |
PerlMonks |
Re: unxpected sort warnings while using sortby marinersk (Priest) |
on Jul 27, 2015 at 02:32 UTC ( [id://1136403]=note: print w/replies, xml ) | Need Help?? |
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:
Notice in the results how median_num()receives two different types of structures:
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:
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 Section
Seekers of Perl Wisdom
|
|