I am trying to get my perl code to log all opened files with code like this:
my @OpenCalls;
BEGIN {
# See: http://www.perlmonks.org/?node_id=909403
*CORE::GLOBAL::open = sub(*;$@) {
push @OpenCalls, [ @_[1..$#_] ];
use Symbol ();
my $handle = Symbol::qualify_to_ref($_[0], scalar caller);
$_[0] = $handle unless defined $_[0]; # pass up to caller
if (@_ == 1) {
CORE::open $handle;
} elsif (@_ == 2) {
CORE::open $handle, $_[1];
} elsif (@_ == 3) {
if (defined $_[2]) {
CORE::open $handle, $_[1], $_[2];
} else {
CORE::open $handle, $_[1], undef; # special case
}
} else {
CORE::open $handle, $_[1], $_[2], @_[3..$#_];
}
};
}
I am running into an issue with OOPerl where my filehandle is disappearing before the call to the DESTROY method:
"print() on closed filehandle PKG:: at PKG.pm line 104 during global destruction
Note that the CORE::GLOBAL::open override happens in a package different than PKG. I am using perl 5.10.0 on linux.
Dear wise Monks, any insights would be appreciated!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|