Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hi anonypl, What I fail to understand is, iterating the array using $thing variable but not using it at all in the loop still gives the expected result. Regardless of whether you use $thing or not, the loop body will normally still be executed once per element of the array. However, as others have already pointed out, your code may be printing the array in reverse order, but doesn't actually reverse the array itself; also note that Foreach Loops says this: If any part of LIST is an array, foreach will get very confused if you add or remove elements within the loop body, for example with splice. So don't do that. Alternative ideas:
Updated in regards to others having already replied in the meantime. Update 2: Actually, in my first example above it isn't really necessary to destroy @arr to build @out, in that regard Laurent_R's idea is better than the first example above. The second example is still applicable, though. Hope this helps, In reply to Re: Array confusion.
by haukex
|
|