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.


In reply to Re: Check if key exist in hash but not exact match - MCE::Shared::Hash by marioroy
in thread Check if key exist in hash but not exact match by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.