Tim:


Per the perldoc:
http://perldoc.perl.org/CORE.html
... you can globally override CORE::GLOBAL::open with your own function.

It was a bit harder to do than I though though...

BEGIN { *CORE::GLOBAL::open = sub (*;$@) { ($package, $filename, $line) = caller(); print "LOGGING: intercepted `open` call from ( package: '$package' +, file: '$filename', line: '$line' ) with args: '??', ".join(", ",map +{ "'$_'" } @_) . "\n"; if(defined($_[0])) { use Symbol qw(); my $handle = Symbol::qualify($_[0],(caller)[0]); no strict 'refs'; if(@_ == 1) { return CORE::open($handle); } elsif(@_ == 2) { return CORE::open($handle, $_[1]); } else { return CORE::open($handle, $_[1], @_[2..$#_]); } } else { if(@_ == 1) { return CORE::open($_[0]); } elsif(@_ == 2) { return CORE::open($_[0], $_[1]); } else { return CORE::open($_[0], $_[1], @_[2..$#_]); } } }; } open(my $fh, "<", ".bashrc") or die "unable to use hacked up open func +tion: $!"; my $top = <$fh>; print $top;

Which returns:
LOGGING: intercepted `open` call from ( package: 'main', file: './core +over.pl', line: '34' ) with args: '??', '', '<', '.bashrc' # ~/.bashrc: executed by bash(1) for non-login shells.
Note: i had done this before, but couldn't quite remember how to make it work with open($fh ..) instead of open(FH ..), so perl.com helped me out:
http://www.perl.com/pub/a/2002/06/11/threads.html?page=2
-- AlexLC

In reply to Re: CORE::GLOBAL::* for auditing which files are read and written? by alexlc
in thread CORE::GLOBAL::* for auditing which files are read and written? by tim.bunce

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.