Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Subphrases from a phrase

by ikegami (Patriarch)
on Aug 10, 2005 at 05:47 UTC ( [id://482521]=note: print w/replies, xml ) Need Help??


in reply to Subphrases from a phrase

I think the following is much easier to read than using map:
sub list { my $words=shift; my @words=split /\s/, $words; my @rv; for my $s (0..$#words) { for my $e ($s..$#words) { push(@rv, join(' ', @words[$s..$e])); } } return @rv; }
And you can keep the optimization yours had:
sub list { my $words=shift; my @words=split /\s/, $words; my @rv = @words; for my $s (0..$#words) { for my $e ($s+1..$#words) { push(@rv, join(' ', @words[$s..$e])); } } return @rv; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://482521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-23 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found