in reply to Package variables and Parse::RecDescent

Your problem here is that my $checksyntax declares a lexical variable, while both $::checksyntax and $TelnetClient::Functions::checksyntax refer to (different!) package variables. For a good introduction read up Dominus' Coping with Scoping.

A different issue is that you can only access package variables out of a grammar of Parse::RecDescent. The grammar itself lives in its own lexical scope (if I understood that correctly). To do so you have to fully qualify them, like $TelnetClient::Functions::checksyntax

-- Hofmator

Replies are listed 'Best First'.
Re: Re: Package variables and Parse::RecDescent
by castaway (Parson) on Jan 07, 2003 at 21:56 UTC
    Hmm, so even though my grammar is in the same block as $checksyntax, by the time it is used the scope of $checksyntax is gone? So I'll have to make it global, hohum.
    C.
      The problem is that your grammar might look to you like a piece of code but is in fact just a string. You could move the definition of that string to any prior place in your program, it doesn't make any difference to Parse::RecDescent (P::RD).

      Your grammar (the string) is taken apart into pieces (parsed) in P::RD and then the code to do the actual work is produced - outside your lexical scope. So apparently it can't access any lexical variables in this scope. The documenation of P::RD says to that:

      The action executes within a special namespace belonging to the active parser, so care must be taken in correctly qualifying variable names

      -- Hofmator