title: using map to extract hash set of (key, value) matching specified value
body: <p>I have been looking for a way to do the following action using the perl function <code>map</code>:
  given a hash, I want to extract the pairs (key, value) in which the value equals or matches a specified parameter.</p>
  
  <p>In my example I want to extract the (key, value) pairs where <code>value = failed</code>, but it could also be an expression (i.e. string starting with A, or a REGEX). That's why I want as a result a hash and not only a table of the keys matching the value.</p>
  
  <pre><code>my %strings = (
      bla =&gt; "success",
      ble =&gt; "failed",
      bli =&gt; "failed",
      foo =&gt; "success",
      blo =&gt; "failed",
      bar =&gt; "failed",
      blu =&gt; "success"
  );
  
  my %failed_s = ();
  
  while (my ($k, $v) = each %strings) {
      if ( $v eq 'failed' ) {$failed_s{$k} = $v};
  };
  </code></pre>
  
  <p>I tried several ways of doing this, but without great results so I think I'm getting confused about references, affectation, results, etc.</p>
  
  <pre><code>my %failed_s = 
      map { { $_ =&gt; $strings{$_} } 
      if ( $strings{$_}./failed/ ) } 
      keys %strings;
  my %failed_s = 
      map { ( $strings{$_} eq 'failed') &amp;&amp;
            ($_, $strings{$_}) } 
      keys %strings;
  
  print "Dumper \%failed_s: \n" . Dumper(\%failed_s);
  </code></pre>
  
  <p>It might be not possible or not effective to use map, in this case, but it would help me (and probably others) to know why.</p>