in reply to Why do I need to shuffle an array by reference?

My guess would be that it is common practice to code the shuffle as a sub so that it can be called rather than replicated in-place. Once you place the routine in a sub, it makes sense to pass the array by reference, as to not do so would mean passing the contents of the whole array as a list, which would become prohibitively expensive for large arrays.

For reference, if you are using the shuffle rather than just coding for the sake of learning, there is an implementation of it available in List::Util which comes as standard if you have 5.8.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.

  • Comment on Re: Why do I need to shuffle an array by reference?