in reply to Re^3: How can I delete an element in a foreach cycle?
in thread How can I delete an element in a foreach cycle?

ok, thank you all for your answers. I like that way: to mark the element as "undef" in foreach cycle and then delete it throught a grep. I understood also the lesson of JavaFan: "there is more than one way to do it". But I'm also searching a way for me. That way must be a little different from the way I usually know (like the construct similar to C/C++), just because from my personal point of view (this is only my vision) I'm using perl just to have shorcuts where other programming languages are using explict constructs. These shortcuts for me are the funny part of perl. Thank you for all the answers.
  • Comment on Re^4: How can I delete an element in a foreach cycle?

Replies are listed 'Best First'.
Re^5: How can I delete an element in a foreach cycle?
by AnomalousMonk (Archbishop) on Feb 28, 2010 at 05:14 UTC
    ... mark the element as "undef" in foreach cycle and then delete it throught [sic] a grep.

    There are indeed many paths in programming as in life, and if you are happy with the one you have chosen, then so, too, I, and wish you well of it.

    But I must say I don't understand your allegiance to for(each). The only reason I can see for using it is to process the array 'in-place': grep will (I think; haven't researched or tested this) create a temporary array, thus possibly effectively doubling the size of the array being processed; thus, if the array just fits into available memory to begin with, you will run into problems.

    But if you're going to use a  grep also, why not just use a  grep period? (However, this question is just idle curiosity.)