Home: Perl Programming Help: Beginner:
how can i do this?? (dont know if this posted)



hanja
Deleted

Mar 26, 2001, 8:37 AM


Views: 337
how can i do this?? (dont know if this posted)

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


Views: 324
Re: how can i do this?? (dont know if this posted)

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


Views: 318
Re: how can i do this?? (dont know if this posted)

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


Views: 316
Re: how can i do this?? (dont know if this posted)

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


Views: 311
Re: how can i do this?? (dont know if this posted)

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