in reply to Check if key exist in hash but not exact match
Various modules in MCE::Shared can be used directly (non-shared construction). Many classes MCE::Shared::{ Array, Cache, Hash, Minidb, and Ordhash } have query capabilities. The query logic lives in MCE::Shared::Base.
See Syntax for Query String using MCE::Shared::Hash. Typically, the "keys" method returns all the keys. Here, a query string is specified to return keys that match a regular expression. Subsequently, depending on the price.
use strict; use warnings; use MCE::Shared::Hash; my $prices = MCE::Shared::Hash->new(); $prices->{'pizza'} = 12.00; $prices->{'coke'} = 1.25; $prices->{'sandwich'} = 3.00; if ($prices->keys("key =~ /cok/")) { print "found the key 'cok' in the hash\n"; } if ($prices->keys("key =~ /cok/ :AND val >= 1.50")) { print "found the key 'cok' in the hash greater than or equal \$1.50\ +n"; } if ($prices->keys("key =~ /cok/ :AND val < 1.50")) { print "found the key 'cok' in the hash less than \$1.50\n"; } __END__ found the key 'cok' in the hash found the key 'cok' in the hash less than $1.50
Q. Why were query capabilities added to MCE::Shared classes?
A. In the context of sharing, the query mechanism is beneficial for the shared-manager process. It is able to perform the query where the data resides versus client-process(es) iterating involving lots of IPC.
|
|---|