Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by Fastolfe (Vicar)
on Oct 26, 2000 at 18:59 UTC ( [id://38628]=note: print w/replies, xml ) Need Help??


in reply to How do I return the first n words of a string?

The first two things that come to my mind:
$_ = "some string with multiple words"; @first_three = (split)[0..2]; # or ($first_three) = /^\s*(\S+\s+\S+\s+\S+)/;
You can probably adapt either of these to your purposes.

Log In?
Username:
Password:

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

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

    No recent polls found