Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
it's a common idiom to use map to create listified hashes map { $_ => 0 } LIST
  1. That's not a chain.
  2. You're starting with a list and ending with a hash.

    The point being, map is being used to manipulate a list to produce another list which only becomes a hash on assignment.

    hgrep (my version at least) is starting with an existing hash; which it manipulates as pairs; and produces a list which might get assigned to construct another hash; or perhaps joined into a string; or chained into map or sort; or any other construct that takes a list.

    Your version destroys the 'hashiness' of the hash by converting it to a list before your function gets its hands on it. Which means you have to accumulate the list into an array internally in order to reconstruct the pairs; before you can manipulate it in a 'hashy' kind of way.

    So you've deconstructed the hash to a list; constructed an array from it; then destructively decomposed that array (with splice) to obtain the pairs for passing to the callback.

    My version skips all that and obtains the pairs directly from the hash using each.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^11: Is there any difference between prototype % and @ ? by BrowserUk
in thread Is there any difference between prototype % and @ ? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found