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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -