Re: How to clear parser variables between invocations of ->parse()?
[email protected] (Colin Kuskie) Wed, 9 Oct 2002 11:03:52 -0700
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Oct 09, 2002 at 09:56:11AM -0400, Ted Zlatanov wrote: > 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. Thanks, that works well, aside from this happening: Use of uninitialized value in index at /users/ckuskie/perl/modules/Parse/RecDescent.pm line 2979. Use of uninitialized value in index at /users/ckuskie/perl/modules/Parse/RecDescent.pm line 2979. Use of uninitialized value in length at /users/ckuskie/perl/modules/Parse/RecDescent.pm line 2734. Use of uninitialized value in substitution (s///) at (eval 21) line 1076. Use of uninitialized value in substitution (s///) at (eval 21) line 1076. You have to pass the rule something to work with: $parse->clear(''); Colin