in reply to Re: Re: playing with map
in thread playing with map

What tye said. Just because you can do something doesn't mean that it isn't also a really stupid idea to do it. Using map or grep in void context is a sign of someone who has picked up bad habits.

UPDATE
I was asked why talking about modifying the input list triggered comments about void context from me and tye. Here is why. The typical bad idiom you see is to use a grep in void context to change the input list. Hence the alarm. Note that it is usually a bad idea to modify the input list when not in void context, but occasionally it may be natural to do that. For instance the input list is temporary, and you want to both filter and modify in an obvious way. Here is an example of a case where it would fit:

return grep s/^FOR_PRINT://, <FILE>;
In my experience these cases tend to be rare.

UPDATE 2
merlyn is right. I would have to work harder to come up with a place where modifying the input list makes sense. Given that I am not feeling well, I don't feel like doing that, and given that I think it is a bad idea, I don't think I should bother...

Replies are listed 'Best First'.
Re: Re (tilly) 3: playing with map
by merlyn (Sage) on Mar 09, 2001 at 21:43 UTC
    return grep s/^FOR_PRINT://, <FILE>;
    But even that can be trivially written as:
    return map /^FOR_PRINT(.*)/s, <FILE>;
    And thus not lose 5 style points for altering $_, which in my all-too-often experience spits out an "attempt to modify read-only value" when I least expect it.

    -- Randal L. Schwartz, Perl hacker