Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

In my RecDescent grammar, I try to set an element of a hash in the main package:
struct: wire {$main::structs{@arg[0]} = @item[1]}
but it doesn't work. Even simpler stuff doesn't work for me:
struct: wire {$main::simple_var = "hello"}
Ideas? dave

Replies are listed 'Best First'.
Re: setting main package vars w/ RecDescent
by RMGir (Prior) on Apr 18, 2002 at 18:13 UTC
    Wierd...

    Are you sure that shouldn't be

    struct: wire {$main::structs{$arg[0]} = $item[1]}
    ? The @arg[0] and @item[1] look suspect.

    I don't understand why your 2nd example doesn't work just fine, though...
    --
    Mike

      Seems I needed to declare the array/variable with:
      use vars qw(%structs);
      first. Not sure what it is really doing, but sure it works!