diotalevi has asked for the wisdom of the Perl Monks concerning the following question:
Hi there, I'm thinking about how to capture perl's parse tree for regular expressions without using Rx (mostly because I don't want to have to use pre-alpha perl + custom patches, partly because it's just an interesting question).
The simplest test for this is closing the STDERR filehandle. This almost works except some text is still printed. The odd bit is if I try try tie STDERR then the tied methods are never even called (except CLOSE AND TIEHANDLE). So what gives? Amy I just totally out of luck here?
Default output:
$ perl -Mre=debug '1 =~ `' Freeing REx: `,' Compiling REx `1' size 3 first at 1 1: EXACT <1>(3) 3: END(0) anchored `1' at 0 (checking anchored isall) minlen 1 Guessing start of match, REx `1' against `1'... Found anchored substr `1' at offset 0... Guessed: match at offset 0 Freeing REx: `1'
After closing STDERR
$ perl -Mre=debug -e 'BEGIN { close STDERR } 1 =~ 1' Freeing REx: `1'
A tied trap fails to do anything useful
re.pl: package TrapRe; sub TIEHANDLE { my $class = shift; my $fh = \do { local *HANDLE }; bless $fh, $class; } sub CLOSE { close $_[0] } sub READ {} sub READLINE {} sub GETC {} sub WRITE {} sub PRINT {} sub PRINTF {} sub BINMODE {} sub EOF {} sub FILENO {} sub SEEK {} sub TELL {} sub OPEN {} sub DESTROY {} sub UNTIE {} package main; use re 'debug'; BEGIN { tie *STDERR, TrapRe; } 1 =~ 1; $ perl re.pl Compiling REx `1' size 3 first at 1 1: EXACT <1>(3) 3: END(0) anchored `1' at 0 (checking anchored isall) minlen 1 Guessing start of match, REx `1' against `1'... Found anchored substr `1' at offset 0... Guessed: match at offset 0 Freeing REx: `1'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trapping re 'debug'
by PodMaster (Abbot) on Jan 27, 2003 at 06:46 UTC | |
by diotalevi (Canon) on Jan 27, 2003 at 07:00 UTC | |
by Anonymous Monk on Jan 27, 2003 at 17:04 UTC | |
by diotalevi (Canon) on Jan 27, 2003 at 17:38 UTC | |
|
Re: Trapping re 'debug'
by John M. Dlugosz (Monsignor) on Jan 27, 2003 at 06:46 UTC | |
by diotalevi (Canon) on Jan 27, 2003 at 07:02 UTC | |
by John M. Dlugosz (Monsignor) on Jan 27, 2003 at 07:42 UTC |