<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div><br></div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;">Also if you glob $FH and FH. I got message below. Localize $FH with my, the message gone.<br><br><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">Attempt to free unreferenced scalar: SV 0x1242a0 during global destruction.</span><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> tiger peng &lt;tigerpeng2001@yahoo.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> Chicago.pm chatter &lt;chicago-talk@pm.org&gt;<br><b><span style="font-weight: bold;">Sent:</span></b> Fri, October 22, 2010 2:11:07 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re:
 [Chicago-talk] logging in and out files<br></font><br>
<div style="font-family: Courier New,courier,monaco,monospace,sans-serif; font-size: 10pt;"><div><span style="font-family: arial,helvetica,sans-serif;">I tried out a working version below. It works for $FH and FH, but I do not know clearly why it works<br><br></span>sub open{<br>&nbsp;&nbsp;&nbsp; my ($package, $file, $line_number) = caller();<br>&nbsp;&nbsp;&nbsp; my $fullpath&nbsp; = Cwd::abs_path($file);<br>&nbsp;&nbsp;&nbsp; my $host = hostname();<br>&nbsp;&nbsp;&nbsp; _open_log({host=&gt;hostname(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; script=&gt;Cwd::abs_path($file),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file=&gt;$_[1],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 );<br>&nbsp;&nbsp;&nbsp; if ($_[0]) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; no strict 'refs';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORE::open("::$_[0]", $_[1]) or die "Cannot open $_[1]: $!\n";<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CORE::open($_[0], $_[1]) or die "Cannot open $_[1]: $!\n";<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>}<br><br></div><div style="font-family: Courier New,courier,monaco,monospace,sans-serif; font-size: 10pt;"><br><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> imran javaid &lt;imranjj@gmail.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> <a target="_blank" href="http://Chicago.pm">Chicago.pm</a> chatter &lt;chicago-talk@pm.org&gt;<br><b><span style="font-weight: bold;">Sent:</span></b> Thu, October 21, 2010 2:46:29 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re:
 [Chicago-talk] logging in and out files<br></font><br>
This might get you somewhere:<br><br>use strict;<br>use Symbol;<br><br>sub myopen {<br>&nbsp; if (ref(\$_[0]) eq 'SCALAR') {<br>&nbsp; &nbsp; open ($_[0], $_[1]);<br>&nbsp; } else {<br>&nbsp; &nbsp; my $in = qualify_to_ref($_[0]);<br>&nbsp; &nbsp; open($in, $_[1]);<br>&nbsp; }<br>}<br><br>myopen(*FILE, "&gt;file.txt") or die $!;<br>print FILE "testing\n";<br>myopen(my $FILE2, "&gt;file2.txt") or die $!;<br>print $FILE2 "testing2\n";<br><br>If you remove "use strict;" then you can replace "*FILE" with "FILE",<br>but can and should are not the same thing.<br><br>-imran<br><br>On Thu, Oct 21, 2010 at 12:34 PM, tiger peng &lt;<a rel="nofollow" ymailto="mailto:tigerpeng2001@yahoo.com" target="_blank" href="mailto:tigerpeng2001@yahoo.com">tigerpeng2001@yahoo.com</a>&gt; wrote:<br>&gt; Thanks, it looks a good tool and I will try it later.<br>&gt;<br>&gt; But my problem now is how to pass in and back the FH.<br>&gt;<br>&gt; It complains with error
 message:<br>&gt; Can't use string ("FH") as a
 symbol ref while "strict refs" in use at<br>&gt; /my/lib/myLogger.pm ...<br>&gt;<br>&gt; When I let it do not complain with "no strict 'refs';", it does not complain<br>&gt; but FH seems not opened or not passed back, as the caller read nothing out.<br>&gt;<br>&gt; ________________________________<br>&gt; From: Joshua &lt;<a rel="nofollow" ymailto="mailto:joshua.mcadams@gmail.com" target="_blank" href="mailto:joshua.mcadams@gmail.com">joshua.mcadams@gmail.com</a>&gt;<br>&gt; To: <a rel="nofollow" target="_blank" href="http://Chicago.pm">Chicago.pm</a> chatter &lt;<a rel="nofollow" ymailto="mailto:chicago-talk@pm.org" target="_blank" href="mailto:chicago-talk@pm.org">chicago-talk@pm.org</a>&gt;<br>&gt; Sent: Wed, October 20, 2010 3:29:53 PM<br>&gt; Subject: Re: [Chicago-talk] logging in and out files<br>&gt;<br>&gt; I haven't done this myself before, but it looks like some folks have<br>&gt; and have put their work on CPAN:<br><span><span>&gt; <a
 target="_blank" href="http://search.cpan.org/%7Ecwest/ex-override-1.1/override.pm">http://search.cpan.org/%7Ecwest/ex-override-1.1/override.pm</a></span></span><br>&gt;<br>&gt; On Wed, Oct 20, 2010 at 9:55 AM, tiger peng &lt;<a rel="nofollow" ymailto="mailto:tigerpeng2001@yahoo.com" target="_blank" href="mailto:tigerpeng2001@yahoo.com">tigerpeng2001@yahoo.com</a>&gt; wrote:<br>&gt;&gt; I wrapped the open as below, and it works for the open $fh, $file but not<br>&gt;&gt; open FH, $file.<br>&gt;&gt;<br>&gt;&gt; As I need to apply the wrapping open function to lots of old script, I<br>&gt;&gt; prefer only add one line: use myLoger 'open'; into the scripts<br>&gt;&gt;<br>&gt;&gt; Is there any suggestion?<br>&gt;&gt;<br>&gt;&gt; sub open{<br>&gt;&gt; &nbsp;&nbsp;&nbsp; my ($package, $file, $line_number) = caller();<br>&gt;&gt; &nbsp;&nbsp;&nbsp; my $fullpath&nbsp; = Cwd::abs_path($file);<br>&gt;&gt; &nbsp;&nbsp;&nbsp; my $host = hostname();<br>&gt;&gt;
 &nbsp;&nbsp;&nbsp;
 _open_log({host=&gt;hostname(),<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; script=&gt;Cwd::abs_path($file),<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file=&gt;$_[1],<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<br>&gt;&gt; &nbsp;&nbsp;&nbsp; CORE::open(shift, shift) or die "Cannot open : $!\n";<br>&gt;&gt; }<br>&gt;&gt;<br>&gt;&gt; sub _open_log {<br>&gt;&gt; ...<br>&gt;&gt; }<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; ________________________________<br>&gt;&gt; From: tiger peng &lt;<a rel="nofollow" ymailto="mailto:tigerpeng2001@yahoo.com" target="_blank" href="mailto:tigerpeng2001@yahoo.com">tigerpeng2001@yahoo.com</a>&gt;<br>&gt;&gt; To: Chicago.pm chatter &lt;<a rel="nofollow"
 ymailto="mailto:chicago-talk@pm.org" target="_blank" href="mailto:chicago-talk@pm.org">chicago-talk@pm.org</a>&gt;<br>&gt;&gt; Sent: Tue, October 19, 2010 11:41:10 AM<br>&gt;&gt; Subject: [Chicago-talk] logging in and out files<br>&gt;&gt;<br>&gt;&gt; Hello all,<br>&gt;&gt;<br>&gt;&gt; Does anyone have the experience on tracing input/output files used by Perl<br>&gt;&gt; script?<br>&gt;&gt;<br>&gt;&gt; I am think if there is anyway to over write the build-in open function, so<br>&gt;&gt; the new open function can log the file name, IO type (R, W, or RW), as<br>&gt;&gt; well<br>&gt;&gt; as the open/close timestamp. Any suggestion is highly appreciated.<br>&gt;&gt;<br>&gt;&gt; Thanks,<br>&gt;&gt; Tiger<br>&gt;&gt;<br>&gt;&gt; _______________________________________________<br>&gt;&gt; Chicago-talk mailing list<br>&gt;&gt; <a rel="nofollow" ymailto="mailto:Chicago-talk@pm.org" target="_blank"
 href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br><span><span>&gt;&gt; <a target="_blank" href="http://mail.pm.org/mailman/listinfo/chicago-talk">http://mail.pm.org/mailman/listinfo/chicago-talk</a></span></span><br>&gt;&gt;<br>&gt; _______________________________________________<br>&gt; Chicago-talk mailing list<br>&gt; <a rel="nofollow" ymailto="mailto:Chicago-talk@pm.org" target="_blank" href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>&gt; <a rel="nofollow" target="_blank" href="http://mail.pm.org/mailman/listinfo/chicago-talk">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>&gt;<br>&gt; _______________________________________________<br>&gt; Chicago-talk mailing list<br>&gt; <a rel="nofollow" ymailto="mailto:Chicago-talk@pm.org" target="_blank" href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>&gt; <a rel="nofollow" target="_blank"
 href="http://mail.pm.org/mailman/listinfo/chicago-talk">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>&gt;<br>_______________________________________________<br>Chicago-talk mailing list<br><a rel="nofollow" ymailto="mailto:Chicago-talk@pm.org" target="_blank" href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br><a rel="nofollow" target="_blank" href="http://mail.pm.org/mailman/listinfo/chicago-talk">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br></div></div>
</div></div></div>
</div></body></html>