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'

In reply to Trapping re 'debug' by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.