[Israel.pm] regex question

lerner at perl-expert.com lerner at perl-expert.com
Sun Jan 25 13:59:59 PST 2004


Hi Yuval

In this case the best thing is to take the entire file into one string .

========================================================
 local $/;
 open VB,"file.bas" or die "etc.";
 $vb=<VB>;
 close VB;

 s/^\s*(Function|Sub) 			# $1 is Function or Sub
	(\s*)(\w+)			# $3 is the Function/Sub name 
	(?!.+?On Error.+?End\s+\1) 	# look ahead to make sure there
is no "On Error"
		(.+?)			# $4 is the Function/Sub body
	(End\s*\1)   			# $5 is the end
    /$1$2$3\nOn Error Goto $3_Error\n$4$5/sgmx
=========================================================
This shuld do the job

Ofcourse you'll have to debug it a bit ....

Bye 
--Itzik



_________
Itzik Lerner   
http://www.Perl-Expert.com
 


> -----Original Message-----
> From: perl-bounces at perl.org.il 
> [mailto:perl-bounces at perl.org.il] On Behalf Of Yuval Zaltz
> Sent: Sunday, January 25, 2004 3:48 PM
> To: perl at perl.org.il
> Subject: [Israel.pm] regex question
> 
> 
> Hi,
>  
> 
> I need to parse a VB file that contains Functions and Subs. 
> 
> In each subroutine and function I need to identify if the 
> string "On Error" exists
> 
> and if not add it.
> 
> what is the most efficient way to do this in regex?
> 
> Thanks Yuval
> 
>  
> 
> The file looks like this :
> 
>  
> 
> .
> 
> .
> 
> .
> 
> Function x
> 
> .
> 
> On Error ...
> 
> .
> 
> .
> 
> End Function
> 
> .
> 
> .
> 
> Sub y 
> 
> .
> 
> .
> 
> .
> 
> End Sub
> 
> .
> 
> .
> 
> .
> 
> Function z
> 
> .
> 
> .
> 
> End Function
> 
> .
> 
> .
> 
>  
> 
>  
> 
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/mailman/listinfo/perl
> 
> YAPC::Israel::2004
> http://www.perl.org.il/YAPC/2004/
> 
> 




More information about the Perl mailing list