in reply to hash substrings
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash substrings
by perlcat (Novice) on Jan 27, 2009 at 09:03 UTC | |
by jethro (Monsignor) on Jan 27, 2009 at 15:06 UTC |