in reply to Trapping re 'debug'

you have to close STDERR before you use re, like
perl -e" BEGIN{close STDERR};use re qw[debug]; 1 =~ 1 "


MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
** The Third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re^2: Trapping re 'debug'
by diotalevi (Canon) on Jan 27, 2003 at 07:00 UTC

    Ok, so I tried that and got marginally closer. At least the "Freeing" line isn't visible anymore. So why isn't PRINT, PRINTF, or WRITE being called with the data? That's really the final bit that would have to work for it to even have a point. The following code outputs nothing except "DESTROY\n".

    package TrapRe; sub TIEHANDLE { my $class = shift; my $fh = \do { local *HANDLE }; bless $fh, $class; } sub CLOSE { close $_[0] } eval qq[sub $_ { print "$_\n" };] for qw/READ READLINE GETC WRITE PRINT PRINTF BINMODE EOF FILENO SEEK TELL OPEN DESTROY UNTIE/; package main; BEGIN { close STDERR; tie *STDERR, TrapRe; } use re 'debug'; 1 =~ 1;

    Seeking Green geeks in Minnesota

      The reason you only see the DESTROY in your class is because you closed STDERR, then tied it to your class, but in your class you do nothing with it. So then when re 'debug' attempts to print STDERR, perl find that the handle is closed and reopens it before it can output to it. This process of reopening destroys your handle. You get the DESTROY call.

        Fair enough. I removed the call to close STDERR, left the tie *STDERR, TrapRe line in and I still only get the 'DESTROY' note. So at that point I'm just tying the existing STDERR handle but the tied object methods aren't being triggered at all.


        Seeking Green geeks in Minnesota