As to the question of grep and map being used as much as they could, I couldn't agree more. At work, I've had to train a few people to use them instead of foreach when they made sense ... and then untrain them a bit when they started using them where they didn't make sense. The point isn't to religiously worship them, but to make your code do what it says: if you're converting one list into another, you're mapping from one to the other. If you're finding elements in a list, you're grepping for them.
By speaking idiomatically perl, you may get a speed benefit (as you did in your benchmark), but, more importantly, you get a maintenance benefit: your code looks like a design document!
That is actually part of the reason why I don't like map's and grep's used in void context - they are no longer reading like plain English. "Map from @common to ... nothing?" Instead, just use for/foreach: "For each element in @common, do..." That reads like exactly the solution you're attempting to do. Which is probably how you're thinking of the problem - and, any time your can code your solution in the domain of the problem instead of the domain of the solution, you're going to end up with clearer and more flexible code.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|