in reply to Re: Best way to remove elem of for loop
in thread Best way to remove elem of for loop

You do not want map(), you want grep().

my @filtered = grep { -d $_ } @ar; # or my @filtered = grep -d $_, @ar;

map() means "process the elements one after another and give me the results", while grep() means "give me only those elements of the list that match the condition".

Jenda
Enoch was right!
Enjoy the last years of Rome.

Replies are listed 'Best First'.
Re^3: Best way to remove elem of for loop
by tobyink (Canon) on Apr 24, 2014 at 18:05 UTC

    Or even:

    my @filtered = grep -d, @ar;
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re^3: Best way to remove elem of for loop
by Preceptor (Deacon) on Apr 25, 2014 at 09:48 UTC

    Yes, spot on. I still think of grep in Unix terms, e.g. pattern matching. I had blanked out the bit where it can take an EXPR to evaluate. Even if I did know that underneath the hood grep and map aren't much different.