in reply to Re^2: Parsing a file to print multiple times
in thread Parsing a file to print multiple times

Try to fill in the blanks (...) to this
my @nums = 1 .. 10; my $start = 3; my $end = 5; my $go = 0; for my $num ( @nums ){ ... if( $go ){ print "$num\n"; } }

Replies are listed 'Best First'.
Re^4: Parsing a file to print multiple times
by ExperimentsWithPerl (Acolyte) on Sep 26, 2015 at 10:21 UTC

    Thanks a lot Anonymous Monk.You rock!!!
    This logic worked.Below is the final code :-

    open (FILE, '<', 'sample.txt') or die "Could not open sample.txt: +$!"; open (FILE1, ">output1.txt") or die "Could not open sample.txt: $! +"; my @nums = <FILE>; my $start = "print from"; my $go = 0; my $sizeconf = scalar @nums; for my $num ( @nums ){ if ($num =~ /$start/) { $go = 1; } if($go){ print FILE1 "$num"; } my $end = "closing"; if ($num =~ /$end/ && $num !~ /$start/) { $go = 0; } }


    The last point of "$num =~ /$end/ && $num !~ /$start/" because in my actual input file $start conatins the staring $end.

    I will intergrate this logic with my tool and update you.

      Yes..this works fine when integrated.