PERL read subsection inside open FileHandler -
i have open file using:
open (fh, "<".$file::find::name) or die "cannot open file \"".$file::find::name." \"!"; while (<fh>) { ...my code... }
i parse lines using regular expressions data want. want read subsection of file until see ending of subsection inside while-loop. i.e: reading "startsection" until "endsection" line line:
open (fh, "<".$file::find::name) or die "cannot open file \"".$file::find::name." \"!"; while (<fh>) { ...my code... if (/^startsection$/) { while (<fh> !~ /^endsection) { ... more code.... } } }
how must program correctly in perl?
i can think of several ways answer question, i'll go flip-flop operator answer:
while (<fh>) { if (/^startsection$/ .. /^endsection/) { ... special code ... } else { ... regular code ... } }
Comments
Post a Comment