Re: How to clear parser variables between invocations of ->parse()?

[email protected] (Ted Zlatanov) Wed, 09 Oct 2002 09:56:11 -0400
Newsgroups perl.recdescent
Organization Теодор Златанов @ Cienfuegos
Message-ID <[email protected]>
On Tue, 8 Oct 2002, [email protected] wrote:
> It works great, except I need to clear %variables between calls to
> $parse->eqns.  I realize that in this instance that:
> 
> $list = ();
> 
> works, but it doesn't feel right.  Something cleaner would be nicer.
> I'd also prefer not to use a global in the main package instead of
> the private namespace variable.
> 
> Isn't there a more encapsulated way to either clear the private
> variable or have a different solution?

I may be missing something, but why not use a function instead of the
eqns rule?

sub run_equation { $parse->clear(); $parse->eqns(@_); };

and then in the grammar implement a clear() rule to clear the
variables.

You could also instantiate a new grammar object, since your grammar
objects basically have a private variable for the variables hash.

Ted