in reply to <SOLVED>Dereferencing arrays
When I run your code, the error you cite occurs on my line 30. It hits because when you call mergeSort on line 51, @leftSide array has 5 elements. Since you've used Prototypes, mergeSort expects a single scalar. However, you undermine the protoype system by invoking your method with &, so Perl stuffs your array in scalar context; thus the array length of 5. The general solution is don't use prototypes unless you actually know how to use them. If you change your code to read:
You will solve this particular issue, though your sort will still fail for the reasons that BrowserUk hints at.mergeSort( @leftSide ); mergeSort( @rightSide ); merge( @leftSide, @rightSide, $data );
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|