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

Hi,

How does one make use of Regexp::Grammars "<log: ...>" directive? I presumed that the following code should output "via log" to the logfile (STDERR in this case) but it never appears.

#!/usr/bin/env perl use v5.32.01; use Data::Dumper; my $parser = do { use Regexp::Grammars; qr{ <logfile: - > <nocontext:> <Yada> <token: Yada> <log: via log> # <warning: via warning> <error: via error> <fatal: via fatal> yada }ixms; if ('yada' =~ $parser) { warn Data::Dumper->new([\@!,\%/],[qw(*! */)])->Deepcopy(1)->Indent +(1)->Maxdepth(0)->Sortkeys(1)->Dump(),q{ }; } else { say {*STDERR} $_ for @!; # i.e. report all errors };

Replies are listed 'Best First'.
Re: Regexp::Grammars' <log: ...> directive
by haukex (Archbishop) on Jul 16, 2022 at 11:52 UTC

    For me, the log message does show up when I turn on debugging via e.g. <debug: run>. Note you need to remove the <error: > and <fatal: > directives for the match to complete successfully. Also, your code doesn't compile, it's missing a closing } on the do block.