Possible Duplicate:
How do I break out of a loop in Perl?
I have data that looks like what you see bellow. I am trying to create a perl script that will capture selected text. My idea of going about it was saying "if the previous line read was all -'s and the current line read is all ='s then stop reading the file and don't print those lines with only ='s and -'s.
However, I don't know how to code that. I only started using perl 3 days ago. I don't know if that is the best way of doing it. Let me know if there is a better way. Either way if you could help with the code, I'd appreciate it.
My code so far:
...
$end_section_flag = "true" # I was going to use this to signify
# when I want to stop reading
# ie. when I reached the end of the
# data I want to capture
while (<$in-fh>)
{
my $line = $_;
chomp $line;
if ($line eq $string)
{
print "Found it\n";
$end_section_flag = "false";
}
if ($end_section_flag eq "false" )
{
print $out-fh "$line\n";
// if you found the end of the section i'm reading
// don't pring the -'s and ='s and exit
}
}
What my data looks like
-------------------------------------------------------------------------------
===============================================================================
BLAH BLAH
===============================================================================
asdfsad
fasd
fas
df
asdf
a
\n
\n
-------------------------------------------------------------------------------
===============================================================================
BLAH BLAH
===============================================================================
...
What I want to capture
-------------------------------------------------------------------------------
===============================================================================
BLAH BLAH
===============================================================================
asdfsad
fasd
fas
df
asdf
a
\n
\n