in reply to multi-dimensional range lookup
As for the data structure to load the lot into for a memory scan, there isn't anything purpose built for your problem (except possibly some linear programming modules that are OTT for your simple need). But whether hoh or aoh is the best fit depends on whether photo_id is numeric without gaps, but the lower level hash should have keys r,g,b with the respective values. Also use Storable and only update it if the database changes to avoiding having to read the whole database every time. To search the hash or array, for the aoh case something like:select photo_id from colors where ( r between 12 and 15 ) and ( g betw +een 78 and 81 ) and b between 23 and 26
for hoh just substitute $array[ $_ ]with $hash{ $_ } in the map statement;my @match = map Filter( 'r', $minred, $maxred, Filter( 'g', $mingreen, + $maxgreen, Filter( 'b', $minblue, $maxblue, $array[ $_ ] ))), @array +; sub Filter { my ( $colour, $min, $max, $href ) = @_; $href or return undef(); ( $href -> { $colour } >= $min ) or return undef(); ( $href -> { $colour } <= $max ) or return undef(); return $href; }
^M Free your mind!
Key to hats: ^I=white ^B=black ^P=yellow ^E=red ^C=green ^M=blue - see Moron's scratchpad for fuller explanation.
|
|---|