Keep It Simple, Stupid | |
PerlMonks |
Re^2: Confusing syntax error with grepby gumpu (Friar) |
on Aug 12, 2004 at 17:25 UTC ( [id://382386]=note: print w/replies, xml ) | Need Help?? |
"However, it also doesn't make sense because you are using grep in a void context. grep is meant to filter a list (reduce some of the contents out of list1 into list2). If you just want to apply a block of code against every item in a list, think of using map or foreach. Most folks here will complain, likewise, if you use map in a void context" Guess I agree on using map instead of grep. But I find foreach ugly.
Is far less pretty to the eye than:
OK, map ( or grep ) has to create a list which is not used. I used to worry about that too. However, given the size of an list in an average problem and the amount of memory that is nowadays present in a computer it is no longer relevant to worry about it. For instance in my case the list holds the names of all files in a single directory. That will be 1 to 1000 elements or so. Compared to the 256 Mbyte that is available in my computer this is peanuts. So I stopped worrying about it and instead worry about making it readable. Of course it would be even nicer if there was a construct in perl like:
Have Fun
In Section
Seekers of Perl Wisdom
|
|