People have posted other solutions. This is probably no worse or no better…
use strict; use warnings; use Data::Dump qw/dd/; my %phrases = ( 'rendition' => '3', 'automation' => '2', 'saturation' => '3', 'mass creation' => 2, 'automation technology' => 2, 'automation technology process' => 3, 'technology process' => 5, 'automation process' => 2, ); sub filter_wordlist_thing { my %output = %{+shift}; for my $key (grep / /, keys %phrases) { my @words = split / /, $key; my @word_combos = grep $_ ne $key, map join(" ", @words[$_->[0]..$_->[1]]), map { my $start = $_; map [$start, $_], $start .. $#words +} 0 .. $#words; delete @output{@word_combos}; } \%output; } dd filter_wordlist_thing(\%phrases);
In reply to Re: retain longest multi words units from hash
by tobyink
in thread retain longest multi words units from hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |