[Israel.pm] recursive regex

Yossi.Itzkovich at ecitele.com Yossi.Itzkovich at ecitele.com
Wed Jun 9 02:43:58 PDT 2004






Shlomo,

It works great !
But if I understand it correctly  it scans the data M+1 times (M=macro).
It is not a problem in my case, just of curiosity.

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                                                                                                       
                                                                                                                                   
                                                                                                                                   



Hello.

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