in reply to read multi lines of a file in perl

Do you want (1) to read only the lines

jdk jhfk

Or (2) should your output also include the start and stop reading tokens, like

process jkdgf jdk jhfk end process
?

For (1), the following code does the trick.

use strict; use warnings; my $print_flag = 0; while (<DATA>) { if (/end process/) { last; } elsif (/process/) { $print_flag = 1; } else { print if $print_flag; } } __DATA__ ghklg process jkdgf jdk jhfk end process

Output:

C:\Perl\src>perl 721648.pl jdk jhfk

Replies are listed 'Best First'.
Re^2: read multi lines of a file in perl
by sharan (Acolyte) on Nov 05, 2008 at 14:32 UTC
    Hi Richb, Thanks for ur reply.. But i still have a small problem.. as this is able to check for only one loop and not repeated loop.. eg
    process lkhls ksjhfk end process process kfhls kfh end process
    i want output as
    ksjhfk kfh
    Thanks....
      flipflop operator to the rescue:
      perl -lne 'print if /^process/ .. /^end process/ and not /^process/ and not /^end process/' process lkhls ksjhfk end process process kfhls kfh end process
      apparently does what you want:
      ksjhfk kfh
      []s, HTH, Massa (κς,πμ,πλ)