locked_user sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:
I’m writing code for Parse::RecDescent which has to deal with file in which newlines (\n) are significant.. (A shell script.)
Clever bear that I am, I wrote code that would set the following value globally... $Parse::RecDescent::skip = qr/[ \t]*/;
Much to my amazement, it didn't work! But the following statement, within the grammar, did: <skip: qr/[ \t]*/>
Notice that the regular-expression is identical. And, the regular-expression is correct.
After losing great quantities of hair-follicles and smashing new holes in my desktop with my fists, I think I discovered the answer ...
If you are going to assign to this variable, you must do it before you instantiate your parser object. When the object is instantiated, it picks up its global skip-expression and keeps it.
In other words, the code worked correctly when I moved the code to assign the global variable, in front of the code that constructed the new parser object.
I was also very surprised to learn that it doesn’t do any good to fiddle with the global variable from within the startup-code of the parser grammar. (Note: I have not attempted to set $skip there.)
If this behavior can be verified, I cordially suggest that it be added to the FAQ. Meanwhile, I’ve got to go bandage my forehead and my fists, and buy a new keyboard...
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Something you need to know about $Parse::RecDescent::skip
by metaperl (Curate) on Nov 03, 2010 at 14:06 UTC |