#!/usr/bin/perl # https://perlmonks.org/?node_id=1219394 use strict; use warnings; use Data::Dump 'dd'; my %phrase_counts = ( 'rendition' => '3', 'automation' => '2', 'saturation' => '3', 'mass creation' => 2, 'automation technology' => 2, 'automation technology process' => 3, 'technology process' => 5, 'automation process' => 2, 'process automation' => 2, ); dd 'before', \%phrase_counts; my $words = ''; for my $w ( sort { length $b <=> length $a } keys %phrase_counts ) { if( $words =~ join '.*?', map "\\b$_\\b", split ' ', $w ) { delete $phrase_counts{$w}; } else { $words .= "$w\n"; } } dd 'after', \%phrase_counts;
In reply to Re: retain longest multi words units from hash
by tybalt89
in thread retain longest multi words units from hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |