note
mnithink
Thanks to all of you for your help.
Based on your guidance i managed to get my code work.
I'm posting my code below.
#!/usr/bin/perl
#use strict;
#use warnings;
my $fh;
my $log;
my $line;
open($fh,"<","file1") or die "can not open file $fh : $!\n" ;
open ($log,">","file2")or die "can not open file $log : $!\n" ;
while($line = <$fh>)
{
if ($line =~ /pattern1/ )
{
printf $log $line;
while($line = <$fh>)
{
if($line =~ /pattern2/)
{
printf $log $line;
last;
} else
{
printf $log $line;
}
}
}
}
close $fh;
close $log;
Happy to take your advice to make this code more efficient.
949225
949307