in reply to retain longest multi words units from hash
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: retain longest multi words units from hash
by LanX (Saint) on Jul 29, 2018 at 21:21 UTC | |
by tobyink (Canon) on Jul 30, 2018 at 10:43 UTC | |
by LanX (Saint) on Jul 30, 2018 at 22:46 UTC |