in reply to Subphrases from a phrase

Update: Mine gives combinations, not "phrases", so may not be a wanted solution. Thanks, ikegami.

Using Math::Combinatorics:

use warnings; use strict; use Math::Combinatorics; use Data::Dumper; my $phrase = 'camel perl book'; my @data = split /\s/, $phrase; my @sets; foreach my $count (1..@data) { my $combinat = Math::Combinatorics->new( count => $count, data => [@data] ); while(my @combo = $combinat->next_combination()) { push @sets, join ' ', @combo; } } print Dumper \@sets;

Replies are listed 'Best First'.
Re^2: Subphrases from a phrase
by ikegami (Patriarch) on Aug 10, 2005 at 02:55 UTC
    I don't think he wants combinations. There are 7 combinations, but he only has 6 results. Your solution lists "camel book", which is not a subexpression of "camel perl book". The difference becomes much more evident when there are four words.