[Israel.pm] recursive regex

Yossi.Itzkovich at ecitele.com Yossi.Itzkovich at ecitele.com
Wed Jun 9 02:54:04 PDT 2004






I have never used in a while loop same file handle in 2 places at the same
time.  Does it mean that each while manages its own position pointer in the
file ?

Yossi



                                                                                                                                   
                      Shlomo Yona                                                                                                  
                      <shlomo at cs.haifa         To:      Perl in Israel <perl at perl.org.il>                                          
                      .ac.il>                  cc:                                                                                 
                      Sent by:                 Subject: Re: [Israel.pm] recursive regex                                            
                      perl-bounces at per                                                                                             
                      l.org.il                                                                                                     
                                                                                                                                   
                                                                                                                                   
                      06/09/2004 12:24                                                                                             
                      Please respond                                                                                               
                      to Perl in                                                                                                   
                      Israel                                                                                                       
                                                                                                                                   
                                                                                                                                   




Is this what you have in mind?

while(<DATA>) {
        print_begin_end_macro($1) if /BEGIN_(\S+)/;
}

sub print_begin_end_macro {
        my ($what)=@_;
        while(<DATA>) {
                if (/END_$what/) {
                        print qq{BEGIN_$what\tEND_$what\n} if /END_$what/;
                        return;
                }
                print_begin_end_macro($1) if /BEGIN_(\S+)/;
        }

}







More information about the Perl mailing list