Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Get same position value in 2nd array

by jethro (Monsignor)
on Dec 18, 2012 at 18:52 UTC ( #1009444=note: print w/ replies, xml ) Need Help??


in reply to Get same position value in 2nd array

From your sentence that starts with "Basically" I would conclude that you have 3 values per item, a scalar aka number(A), a string(B) and another value(C). I would guess A has duplicate values (0 for example)? Does B have duplicate values? Does the combination of A and B have duplicate values?

What is the operation that you have to do the most? Checking for values greater than zero? Or searching for C given A and/or B ?

These questions are all important. For example if B has no duplicate values and you most often have to search for C given B you might just use B as key and a subhash or subarray with A and C as data:

$h{$B}= {'number'=>$A,'value'=>$C}; print $h{$B}{value}; if ($h{$B}{number}>0) { ...

Or if checking for values greater than zero is your main activity and most of the scalars(A) are zero then it might even be sensible to split the data into two arrays (or hashes), one for all data with A==0 and another for the data with A>0.


Comment on Re: Get same position value in 2nd array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-07-31 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls