in reply to Re^4: How can I delete an element in a foreach cycle?
in thread How can I delete an element in a foreach cycle?
@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'.
|
|---|