I would rather sort the keys in ascending order (of key length), store them in an array, and compare the elements of that array, something like:
use strict; use warnings; my %h = ( 'this is a test' => 2, 'is a test' => 2, 'a test' => 1 ); my @keys = sort {length $a <=> length $b} keys %h; for ( 0 .. $#keys-1){ if ($keys[$_+1] =~ /$keys[$_]/){ delete $h{$keys[$_]}; } }
Hope this helps
citromatik
In reply to Re: hash substrings
by citromatik
in thread hash substrings
by perlcat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |