in reply to Check if key exist in hash but not exact match
Maybe like this:
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11151448 use warnings; my %prices; $prices{'pizza'} = 12.00; $prices{'coke'} = 1.25; $prices{'sandwich'} = 3.00; for my $key ( sort keys %prices ) { $key =~ m<(.+)(?{ $prices{$1} //= $prices{$key} })(*FAIL)>; } #use Data::Dump 'dd'; dd \%prices; if (exists($prices{'cok'})) { print "found the key 'cok' in the hash\n"; }
Outputs:
found the key 'cok' in the hash
|
|---|