If I were implementing such a "have I got that item in my list?" function, I would also include in the code the "key" to where in the list that item is, just in case I will want to do something to that item. Now, if we use a hash, then we get that:
Otherwise, if I have a function that tells me whether the item is in the list, I would have the return value being a logical false if the item was not found, or the direct key to it if it was found. If you are doing a simple logical test, then returning a defined value is (should be) accepted as "true" (see page 20 - 21 "What is Truth" of the Camel book).$my_hash{$key_value} = 'Stuff up the value real good';
If it wasn't first thing in the morning, I would attempt to hack a bit of code demonstrating this, but I am sure you all know what I mean here. The essence of what I am saying is that a good programmer looks ahead, and allows for the foreseeable future requirements.
Updated: Stupid typo in code fragment fixed. I should finish my coffee before coding.
In reply to Re: Beauty is in the eye of the beholder
by Maclir
in thread Beauty is in the eye of the beholder
by ChOas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |