Dear All
This code is working fine.
open FILE, c:/sample.txt or die Cannot open $file: $!;
while (FILE) {
#print $_;
if (/^\s*\[record_1\]/ .. /^\s*\[record_2\]/) {
print $_; # note that starting/ending lines will print
}
}
close FILE;
Regards
-Original Message-
From: $Bill Luebkert [SMTP:[EMAIL PROTECTED]]
Sent: Wednesday, July 10, 2002 6:02 PM
To: Erich C. Beyrent
Cc: [EMAIL PROTECTED]
Subject: Re: Help with file parsing
Erich C. Beyrent wrote:
Hey everyone,
I have a file that looks like:
[record_1]
here=20
is=20
some
text
[record_2]
and=20
some
more
[record_3]
...
What I am trying to do is open the file and print all the lines in =
between particular record sets. However, my pattern matching skills =
are not what they ought to be
because I cannot get this to work.
If I want to print all the text in between [record_one] and =
[record_two], how do I do this?
Here is a sample of my code:
open (FILE, $file) or die Cannot open $file: $!\n;
while (FILE)
{
my $line = @_;
# We know which record to start at, and want to
# grab all the text until the next record
if (/^[record_one]/ .. /^[+[A-Za-z]+]/)
{
print $line\n;
}
}
close FILE;
I am a Perl novice, so don't laugh too hard when you look at my code...
Thanks in advance for your help!
In addition to the other replies that should work, I'll stick with
your code and make a few changes:
open FILE, $file or die Cannot open $file: $!;
while (FILE) {
if (/^\s*\[record_one\]/ .. /^\s*\[\w+\]/) {
print $_; # note that starting/ending lines will print
}
}
close FILE;
--
,-/- __ _ _ $Bill Luebkert ICQ=162126130
(_/ / )// // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /-- o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/__/_/_ Castle of Medieval Myth Magic
http://www.todbe.com/
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
**
This email (including any attachments) is intended for the sole use of the
intended recipient/s and may contain material that is CONFIDENTIAL AND
PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or
distribution or forwarding of any or all of the contents in this message is
STRICTLY PROHIBITED. If you are not the intended recipient, please contact
the sender by email and delete all copies; your cooperation in this regard
is appreciated.
**
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs