Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Answer: How do I return the first n words of a string?

by princepawn (Parson)
on Oct 26, 2000 at 20:23 UTC ( #38661=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > How do I return the first n words of a string? - Answer contributed by princepawn

Time for some Perl Golf:
$str= 'yo ho ho and a bottle crumbs. hangin and bangin in the upper-class slums.'; @word = ($str =~ /(\w+)/g); print join ':', @word[0..4];

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[Lady_Aleena]: I'm on Linux/
[beech]: isn't 2 year about standard recovery time for that kind of surgery?
[Discipulus]: if you hate FIle::Find
[Lady_Aleena]: I don't hate it, it just drives me crazy.
[Discipulus]: LA the solution is portable to whatever
[Lady_Aleena]: File::Find doesn't have a simple sub wanted example, like get the name of the file.
[Discipulus]: there is also find2perl with your perl installation

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-04-23 20:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (432 votes). Check out past polls.