Using 'map' as a 'grep' :)
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11143876 use warnings; my %hash; @hash{1..26} = 'a' .. 'z'; my %want = map { $hash{$_} =~ /c|x/ ? ($_, $hash{$_}) : () } keys %has +h; use Data::Dump 'dd'; dd \%want;
Outputs:
{ 3 => "c", 24 => "x" }
In reply to Re: How to grep for values & see the keys?
by tybalt89
in thread How to grep for values & see the keys?
by misterperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |