|XP is just a number|
Re^2: Hash table manipulationby spazm (Monk)
|on Jul 11, 2011 at 21:52 UTC||Need Help??|
David's post works, given my understanding of the orginal post.
Original poster, your question would be helped by example data. Here is the assumption we are working with.
1) Your data set contains keys which are floats and values containing URL strings. e.g.
2) you wish to extract the values for which the keys meet certain properties, in your example "key > 0.4"
3) you wish to do something with the values and/or keys that match the properties. "Now, what modification i want is, i just want to filter the hash keys for example, i want only the values greater than 0.4 and its correct url as a output rather than all random numbers in key.."
Put that all together:
Why the anonymous subroutine for the fitness function? This is to factor out the matching logic from the routines needed to implement the logic. We could put this into a subroutine that takes a sub-ref for the fitness function and returns the wanted keys/value/output generically.
This can be extended to be more generic by passing in the hash to the fitness function within find_good_keys.
This may seem overkill for the "keys > .4" case, but is lovely for a more complex question like "keys between .3 and .7 inclusive, where the value contains foo (case insensitive)."