develooper Front page | perl.macperl.anyperl | Postings from August 2003

recursive regex

Thread Next
From:
Nicholas Thornton
Date:
August 28, 2003 01:22
Subject:
recursive regex
Message ID:
20030828082014.84739.qmail@web20503.mail.yahoo.com
I have a regex I'm performing on a file that takes a
given string, manipulates it, and replaces the string
with the new string. I want this do be done
recursively on each line in case there are multiple
sections that need to be dealt with. I'm currently
using something like:

while(<$file>){
	WHILE:while() {
		if ($string =~ /begin(.*?)end/) {
			my $perl = $1;
			my $eval = eval $perl;
			$string =~s/begin.*?end/$eval/;
		} else {last WHILE}
	}
}

It looks sort of clunky to me, and I don't trust the
subsitution even if it does work, but I can't seem to
get it to work using $perl or $1 in place of the
/.*?/. I was wondering if anyone had any suggestions
for making it nicer, shorter, or cleaner?

~wren

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About