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?

The JavaFan code works for sure, but it looks like c/c++ way: incrementing a number, you've got the index reference... but it doesn't appear too pearlish. There is a way to do it in a more perlish way? AnomalousMonk, I don't understand perfectly your code. You see, I'm only a novice. Please, Can you do a better explains?
  • 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 27, 2010 at 15:32 UTC
    @array = grep !defined || $_ ne 'hello', @array;

    The grep built-in function takes a list (in this case supplied by @array) and returns only those elements of the list for which the BLOCK or EXPRESSION of the function evaluates true. In this case, the expression is
        !defined || $_ ne 'hello'
    and only elements of the input list that are either not defined or not string-equal to 'hello' are output. A better name for the  grep function might be 'filter'.

Re^5: How can I delete an element in a foreach cycle?
by JavaFan (Canon) on Feb 27, 2010 at 16:46 UTC
    One of the mottos of Perl is "there's more than one way of doing it". Thinking one way is "more Perlish" than another is very unPerlish.

    If you want to eliminate everything that Perl borrowed/copied from C, you're left with an utterly useless language not many people will use.