in reply to How can I delete an element in a foreach cycle?
@array = qw(hi hello howdy); @array = grep {!/^hello$/} @array; print join "\n", @array;
If you need to do this in the context of a loop, perhaps it would make sense to combine loop control with undef and filtering after the loop:
@array = qw(hi hello howdy); for (@array) { if ($_ eq 'hello') { undef $_; next; } # Process list elements } @array = grep {defined} @array; print join "\n", @array;
|
|---|