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

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

( #159473=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I return the first n words of a string? contributed by Zombie Wyzelli

Golf swings on...
$str = 'yo ho ho and a bottle crumbs. hangin and bangin in the upper-class slums.'; print join ' ', (split /\s+/, $str)[0..4];

Comment on Answer: How do I return the first n words of a string?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-07-06 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls