Think about Loose Coupling | |
PerlMonks |
Re: Array confusion.by Marshall (Canon) |
on Feb 15, 2017 at 03:30 UTC ( [id://1182044]=note: print w/replies, xml ) | Need Help?? |
I think that the problems of modifying a foreach loop array within the loop have been explained well in other posts. You said: Trying to reverse the array contents without using the "reverse" function... I haven't bench marked this, but making a copy of an array is usually a relatively fast operation. I suspect "rotating" an array by decreasing its size by one item and then increasing its size by one item is more "expensive" than making a copy which is then consumed (size decreases at every access). The basic issue with your code is the use of foreach and modifying the array that foreach is iterating over within the loop. Consider this simple idea:
In Section
Seekers of Perl Wisdom
|
|