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: Beginner:
how can i do this?? (dont know if this posted)

 



hanja
Deleted

Mar 26, 2001, 8:37 AM

Post #1 of 5 (242 views)
how can i do this?? (dont know if this posted) Can't Post

Ok lets say I have this file,

--

Author : Hal Sparks
ID number : id123456
Release number : 21.00
Feature : not important
File name : example.txt
Date : 02/15/2001
Paragraph Requirement Last Modified Releae
123-bb-4.d HOUSE-Page-1 21.00
342-xx-2.a HOUSE-Page-23 21.00

--

My question is how can I only read and record only certain parts of this file. The only information that I need is author, id number, date, and paragraph/requirement/last modified release. And what kind of variable should I store the information??

Thanks.



MattWilliams
Deleted

Mar 27, 2001, 12:19 AM

Post #2 of 5 (229 views)
Re: how can i do this?? (dont know if this posted) [In reply to] Can't Post

Can you be a bit more specific as to what you would like to do once you extract the data, a scenario normally helps



hanja
Deleted

Mar 27, 2001, 5:15 AM

Post #3 of 5 (223 views)
Re: how can i do this?? (dont know if this posted) [In reply to] Can't Post

Sure and thanks replying. After I have the author's name and the neccesary information, I will use that info in a table to display the results.



Jean
User


Mar 27, 2001, 5:43 AM

Post #4 of 5 (221 views)
Re: how can i do this?? (dont know if this posted) [In reply to] Can't Post

Try something like this:


Code
open(FILE, "example.txt") or die "Error: Unable to open file example.txt\n"; 
while ($line = <FILE>) {
if ( $line =~ /Author\s*:\s*(.*)/ ) {
$author = $1;
}
if ( $line =~ /Date\s*:\s*(.*)/ ) {
$date = $1;
}
# Use the previous example to find whatever you need ...
# If Paragraph Requirement is spanned on next fixed number of lines,
# you can read the next lines in the following way: $line = <FILE>;
}

Jean Spector
QA Engineer @ Extent Technologies, Ltd.
mage@lycosmail.com


hanja
Deleted

Mar 27, 2001, 11:32 AM

Post #5 of 5 (216 views)
Re: how can i do this?? (dont know if this posted) [In reply to] Can't Post

Thanks Jean! Your example helps me out a lot but I need to brush up on my regular expressions a bit. Thanks again :)


 
 


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

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