Problems? Is your data what you think it is? | |
PerlMonks |
RFC: Text::Grapby kwaping (Priest) |
on Jul 12, 2006 at 21:24 UTC ( [id://560827]=perlmeditation: print w/replies, xml ) | Need Help?? |
I was thinking about how grep is so easy to use, yet must iterate through every item of a list, becoming a problem if you have a large list. I came up with this simple module as a counterpart if you just want to know if an item is a list member or not. This is version 0.01 so I'm open to suggestions! My goal is to create a function that has as similar of an iterface as possible to the grep builtin, but can be used more effectively in a logical yes/no context. I'm aware that my ($item) = grep(/$pat/,@list); stops grep upon the first successful match. However, I feel that this code is a little awkward to use in the aforementioned logical context. And to use it...
Update 1: Code changed to reflect betterworld's suggestions. --- It's all fine and dandy until someone has to look at the code.
Back to
Meditations
|
|