CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Frequently Asked Questions:
How do I process each word on each line?

 



Jasmine
Administrator

Mar 15, 2001, 6:04 AM

Post #1 of 1 (21467 views)
How do I process each word on each line? Can't Post

How do I process each word on each line?

Use the split function:


Code
    while (<>) { 
foreach $word ( split ) {
# do something with $word here
}
}

Note that this isn't really a word in the English sense; it's just chunks of consecutive non-whitespace characters.

To work with only alphanumeric sequences, you might consider


Code
    while (<>) { 
foreach $word (m/(\w+)/g) {
# do something with $word here
}
}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives