in reply to retain longest multi words units from hash
#!/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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: retain longest multi words units from hash (updated)
by LanX (Saint) on Jul 28, 2018 at 15:32 UTC | |
|
Re^2: retain longest multi words units from hash
by LanX (Saint) on Jul 28, 2018 at 16:57 UTC | |
by tybalt89 (Monsignor) on Jul 28, 2018 at 20:09 UTC | |
by LanX (Saint) on Jul 28, 2018 at 20:38 UTC |