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 | |
by massa (Hermit) on Nov 05, 2008 at 15:01 UTC |