in reply to How to grab Parse::RecDescent error output in a variable?
However, fine as it is though hairy, this will not produce any content in $ParseError
open '>&' results in a dup system call, so it only works on file handles that have a file descriptor. File handles to scalars aren't real file handles, so the OS doesn't know about them, so the OS can't dup them.
Since the ERROR filehandle is defined at module use time, it is necessary to do STDERR munging in a BEGIN block
Actually, it occurs at module execution time. The module is only executed the first time the module is required.
Anyway, it would be cleaner to re-open Parse::RecDescent::ERROR.
use Parse::RecDescent qw( ); ... open(local *Parse::RecDescent::ERROR, '>', \my $error); my $p = Parse::RecDescent->new($grammar) or die "Invalid grammar"; my $output = $p->startrule($str) or die $ParseError;
This method
since use implies a BEGIN block itself?
Did you not read use at that point?
use Parse::RecDescent;
is equivalent to
BEGIN { require Parse::RecDescent; Parse::RecDescent->import(); }
And yes, BEGIN blocks can be nested. A BEGIN is executed as soon as it is fully compiled, so the following prints "abcde":
print("d"); BEGIN { print("b"); BEGIN { print("a"); } # inner BEGIN executed after this line is compiled print("c"); } # outer BEGIN executed after this line is compiled print("e"); # outermost scope executed after this line is compiled
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to grab Parse::RecDescent error output in a variable?
by vrk (Chaplain) on Sep 15, 2008 at 08:07 UTC | |
by ikegami (Patriarch) on Sep 15, 2008 at 12:00 UTC | |
by tfrayner (Curate) on Sep 15, 2008 at 13:09 UTC | |
by Pic (Scribe) on Sep 15, 2008 at 17:12 UTC | |
by vrk (Chaplain) on Sep 17, 2008 at 08:21 UTC |