Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: Need to find and extract words from text file Posted by Jonathan on 22 Jan 2003 at 2:10 PM
Hi,

: I know this is done with regular expressions, but I don't know how. I have text file that contains many lines of information. How would I find the line that contains the word "subject:". Then once that line is found how would i get only the text after the colon in to a variable? For example, let say the line is in row 56 and it looks like this: "subject: ORDER CONFIRMATION". How would I find the subject, and how do I get the "ORDER CONFIRMATION". I need to find the subject and only get the subject.


OK, I'm still trying to get better at reg exp myself, but I think I may have the answer to this one.

open FILE, "<textfile.txt";
while (<FILE>) {
     if (/subject\: (.*)/) {
          $whatyouwant = $1;
     }
}
close FILE;


Let me know if that works, I gotta run deal with something so can't test it right now.

Hope this helps,

Jonathan

-------------------------------------------
Count your downloads:
http://www.downloadcounter.com/
And host your site:
http://www.incrahost.com/
Don't say I never give you anything...

Thread Tree
myname182 Need to find and extract words from text file on 21 Jan 2003 at 4:38 PM
Jonathan Re: Need to find and extract words from text file on 22 Jan 2003 at 2:10 PM
indiabhushan Re: Need to find and extract words from text file on 3 Mar 2003 at 2:57 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.