in reply to Best way to remove elem of for loop
What you're doing is inserting '' into your array. You probably don't want to do this.
I would generally suggest you don't want to try and modify your array, and instead consider just creating a new one, with the filtered elements.
In 'foreach' terms, because 'map' makes my brain hurt:
my @filtered; foreach my $element ( @arg ) { if ( -d $element ) { push ( @filtered, $element ); }; }
If you really want to do an inplace modification, then you may want to look at setting your element 'undef'.
With map, this would probably be something like (for the sake of my own curiosity):
my @filtered = map { -d $_ ? $_ : () } @ar;
.... I think. Anyway, I prefer the former which I consider way more readable.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Best way to remove elem of for loop
by Jenda (Abbot) on Apr 24, 2014 at 17:47 UTC | |
by tobyink (Canon) on Apr 24, 2014 at 18:05 UTC | |
by Preceptor (Deacon) on Apr 25, 2014 at 09:48 UTC | |
|
Re^2: Best way to remove elem of for loop
by HarryPutnam (Novice) on Apr 25, 2014 at 21:14 UTC |