We don't bite newbies here... much | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
This is ugly, but to make this approach work, use a hash and remove a loop with a grep. and if you like one liners, or simplicity, that becomes BTW: What is @array2 doing? It is useless unless you include it in the final line too. Now to your issue of fun things that happen when you edit an array that is used in the controlling loop: Yes, that can mess things up. That is part of the reason that you're better off avoiding loops when you're getting rid of data. List operators, like grep and map eliminate a lot of the need for explicit loops. Assigning a value to @array1 won't force change its scope. That will do the equivalent of empty all items from the list, and then push the new ones on to the end. No new variables will be created or destroyed. If you really like managing loops and arrays yourself, use for instead of foreach, keep an index, and use splice to remove stuff. will remove the 7th element (remember to count from 0) from the array. Hope this helps -- dougIn reply to Re^2: Answer: How do I completely remove an element from an array?
by doug
|
|