|
-
Oct 17th, 2001, 08:07 AM
#1
Thread Starter
Addicted Member
selecting between records
Using perl, I want to pick up only the records between Start and Finish in INFILE:
i.e
Start
AAH
BBH
CCH
Finish
I am using the following code but this only excludes Start and writes everything else to output.txt ?
my $sField = "Start";
foreach $_ (<INFILE> ) {
if ($_ !~ $sField) {
print OUTFILE;
}
}
-
Oct 17th, 2001, 01:48 PM
#2
Black Cat
Try this, I think it's a little clearer as to what's going on:
Code:
use strict;
my $infile = 'file.txt';
my $found = 0;
open(INFILE, $infile) or die "Can't open $infile: $!\n\n";
foreach my $line (<INFILE>) {
if ($line =~ /Start/) {
$found = 1;
} elsif ($line =~ /Finish/) {
$found = 0;
} elsif ($found == 1) {
print OUTFILE $line;
}
}
Josh
Get these: Mozilla Opera OpenBSD
I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|