> -----Original Message----- > From: Bryan R Harris [mailto:[EMAIL PROTECTED]] > Sent: Monday, June 24, 2002 2:58 PM > To: [EMAIL PROTECTED] > Subject: RE: when to use hashes... > > > > > Use a hash when you want to access data by a key. > > > >> (like "if you have over 500,000 items, use a 2-d > >> array instead of a hash") > > > > Perl doesn't have 2-d arrays. > > Sure it does, it just takes a little more work to implement them. =)
Nah, really. It doesn't. > > > > If you have 500,000 of something, that gets in to > > the realm of "a lot". A database may be the best > > answer. Or not. It depends... > > So about how many keys do you have to have before you start > questioning > whether you should be using a hash? Is 15,000 keys too many? > > I've got lots of data files with 15000+ x,y,z values. The > x,y values are > the same, but the z's are different between the files. I > want to output > only data points where ALL the z's in all files for a given > x,y are greater > than 0. Should I load the x,y values as hash keys, and the > max z values as > the "value"? Well, maybe that's the right thing to do. How are the files organized? Are the x,y pairs in the same sequence in each file: File 1 File 2 ------ ------ 10,15,8 10,15,-2 -14,22,3 -14,22,612 19,47,52 19,47,18 If so, you could just read a line from file 1 and then read a line from file 2, knowing that the x,y from file 2 corresponds to the x,y from file 1. Then compare the Z's and print if they fall within your limits. No need for a data structure at all. OTOH, if the lines in File 2 are unpredictable with respect to those in file 1, then yes, you'll most likely want a hash. $hash{$x}{$y} = $z; Now when I read a line from file 2, I can find file 1's Z value by a hash lookup: $hash{$x}{$y}; If the values for x and y are all non-negative integers less than some value (2^32 would be an absolute upper limit, I supposed), you could use array indexes instead of hashing: $arr[$x][$y] = $z; But this kind of thing is *not* the typical situation where folks are being encouraged to use hashes instead of searching through arrays... Which is why, as always, *It Depends* -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]