|There's more than one way to do things|
Re^2: How to grab Parse::RecDescent error output in a variable?by vrk (Chaplain)
|on Sep 15, 2008 at 08:07 UTC||Need Help??|
About the use of require in this example... Here is a complete working example that captures Parse::RecDescent output in a dup'd anonymous filehandle, which shows that use and require are not equivalent in this case.
Running this you will get the output
Now, if you change require at line 13 to use,
Here, the first two lines are printed to STDERR, while the last one indicates that nothing is captured in the dup'd filehandle. Regardless of what the documentation says about use being equivalent to require Module; import Module;, this example shows that it is not the case this time.
Anyway, it would be cleaner to re-open Parse::RecDescent::ERROR.
Yes, it definitely would be. This is what I tried first. Here is a complete example (did you try to run your own example code?):
Clearly format has a side-effect that prevents the use of the nice solution this time. Besides that, your re-open of ERROR requires knowledge of the package internals, while redirecting STDERR requires arguably less knowledge, and certainly not the name of a private (albeit package global) variable.