Here's another way to do it, and the nice thing about this way is that
you can reuse the sub later. This subroutine will print every line
starting after the $start phrase and until it finds the $end phrase.
#######################################
PrintSection("myfile.txt","tools:","not a target:") || die "Couldn't
find a match!\n";
sub PrintSection{
my ($file,$start,$end) = @_[0..2];
my $print = 0;
open(TARGET,"$file") || return 0;
while(<TARGET>){
if($_ =~ /$start/i){
$print = 1;
next;
}
if($_ =~ /$end/i){
return 1;
}
if($print){
print $_;
}
}
close TARGET;
return 1;
}
#######################################
-----Original Message-----
From: Sidharth [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 03, 2004 12:44 PM
To: [EMAIL PROTECTED]
Subject: printing contents between lines
hi all ,
consider the contentes of file as below
<snip>
how to print all the line between tools: and # Not a target:
only
<snip>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>