in reply to Subphrases from a phrase

You missed one combination, "camel book":

#! perl -slw use strict; use List::Util qw[ sum ]; sub Cnr{ my( $n, @r ) = shift; return [] unless $n--; for my $x ( 0 .. ($#_ - $n) ) { push @r, map{ [ $_[$x], @$_ ] } Cnr( $n, @_[ ($x + 1) .. $#_ ] ); } return @r; } our $N ||= 0; print map "@$_\n", Cnr( $N, @ARGV ) and exit if $N; print map{ "@$_\n" } Cnr( $_, @ARGV ) for 1 .. @ARGV; __END__ P:\test>cnr camel perl book camel perl book camel perl camel book perl book camel perl book

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^2: Subphrases from a phrase
by graff (Chancellor) on Aug 10, 2005 at 01:49 UTC
    It's entirely possible that the OP does not want "camel book" to be among the outputs in this example -- the task may be limited to all possible substrings consisting of single words or two or more adjacent words in sequence.

      Good point. I hadn't looked at it that way.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.