Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: How to check if a variable's value is equal to a member of a list of values

by sundialsvc4 (Abbot)
on Mar 25, 2013 at 15:06 UTC ( #1025322=note: print w/replies, xml ) Need Help??

in reply to How to check if a variable's value is equal to a member of a list of values

Most commonly, I stuff the values as hash-members with a do-nothing value of '1' for each entry, just as you suggested in the OP.   But I have also iterated through a list e.g. with the grep() function and don’t often see much difference ... because my applications are not starving for microseconds (like, e.g. the high-performance applications frequently written by BrowserUK in which this governs the whole design) and the entire list is of such a size that it all fits in real-memory anyhow.   You probably have the luxury of choice in this case, where your decision does not seem to be “forced” by this one consideration alone.

Probably, I would let my design be guided by what else you need to do with this list of numbers, and with the data that is associated with them.   Is it, literally, just a list of numbers, such that you only have to see if the number exists and such that, having done so, there is absolutely nothing else associated with that number?   Questions like that.

  • Comment on Re: How to check if a variable's value is equal to a member of a list of values

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025322]
[shmem]: well finally.
[stevieb]: nice! I just finished a GPS "take me home" device last week, and did a bunch of software updates to it yesterday. I also created a pseudo chip with an Arduino to simulate an IC, where it responds to register read/writes over the I2C bus...
[stevieb]: ...from an I2C master. It's ugly and there are many changes I'm going to make, but I had not done anything like it before. It's designed for my RPi:: automated test platform; a system that does CI on *all* my RPi modules.
[shmem]: pseudo chip?
[stevieb]: well, what happens is the Arduino 'listens' for requests r/w, and does the appropriate thing when it's interrupted based on the 'register' address sent in. It's ugly as it was my first attempt, but I've got great new ideas I'm just sitting.
[stevieb]: ...down to implement now. Here's the sketch as it currently sits
[shmem]: well I use I2C and SPI and stuff, but creating a pseudo chip looks to me like lot of indirection and memory clutter... not?
[choroba]: Are you going to use the device soon? Related to your comment about "not having much time to do a lot of coding"...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-06-25 22:40 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (572 votes). Check out past polls.