[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] passing regexp to routine



Carl Johan Berglund writes:
|At 18.36 +0200 98-06-09, Brian "L." Matthews wrote:
|>Yes: last if /$regex/o;
|That's OK if you always want to call the subroutine once, but if you call
|the same subroutine again with another $regex string, perl will continue
|using the old compiled regex, because of the /o. It means once, not once
|per subroutine call.

Yes, Carl is quite right.

|To really recompile the regex only when calling the subroutine, we could
|use the fact that the null pattern ($var =~ //;) defaults to the last
|successfully executed regex.

I think you could also use eval, like (untested):

eval
{
	while (<DATA>)
	{
		handle $_ if /$regex/o;
	}
}

although I'd want to run some Benchmarks before committing to either.

Brian

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch