Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Code Interpretation

by sundialsvc4 (Abbot)
on Jul 30, 2014 at 13:04 UTC ( #1095612=note: print w/ replies, xml ) Need Help??


in reply to Code Interpretation

When they say that Perl is the Swiss Army® Knife of pragmatic data processing, this feature ... array slices ... is definitely one of the things that they’re talking about.   The list of values in hash %uni_refs is sorted (but sorted numerically), then used to take a slice from @allrefs.

Two comments ...

First comment:   “comments!”   This kind of “golf” needs to be preceded by a careful explanation to the future reader as to exactly what this bit of magic is supposed to be doing.   The fact that you had to go to PerlMonks, and that quite a bit of discussion ensued, is a dead-giveaway that in a production setting this code is quite obscure.

Second comment:   this code is very trusting.   That there will be an element in @allrefs for every value in the hash, and that duplicates, if they occur, are not a concern.   If code like this is subjected to the vagaries of actual data, well, “it’s efficient!” ... yes ... but it could also easily produce unexplained behavior farther down the line.   (And, due to the design of slices, any modifications to the returned elements will carry through to make changes to @allrefs.)   So, I personally wouldn’t write it this way.   I don’t fear inefficiencies.   But, I hate surprises.


Comment on Re: Code Interpretation
Re^2: Code Interpretation
by Anonymous Monk on Jul 30, 2014 at 13:39 UTC
    And, due to the design of slices, any modifications to the returned elements will carry through to make changes to @allrefs.

    Modifying @refs will not modify @allrefs.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1095612]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-09-20 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (153 votes), past polls