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?

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

Q&A > strings > How do I return the first n words of a string? 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];

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 studying the Monastery: (16)
As of 2014-09-22 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (200 votes), past polls