<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial,helvetica,sans-serif;font-size:10pt"><div>Alex,<br><br>I am trying create a module, say myLog.pm, to override the built-in open function, adding auxiliary abilities (logging the file access information). <br>I am looking for minor modification, adding one line "<span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">use myLog 'open';'</span> in a hundreds of scripts. The developing module works for the scripts without using typeglob filehandle (open FH, $filename); if no using "use stricts", it also works for the typeglob filehandle.<br><br>It seems after overriding, the compiler take the 'FH' in the open function as calling a subroutine. <br><br><br>Tiger,<br></div><div style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"><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> Alexander Danel &lt;danel@speakeasy.net&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> Mon, October 25, 2010 3:10:10 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Chicago-talk] logging in and out files<br></font><br>



 
 

 

<style>
<!--
 
 _filtered {font-family:Tahoma;panose-1:2 11 6 4 3 5 4 4 2 4;}
 
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;margin-bottom:.0001pt;font-size:12.0pt;font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:blue;text-decoration:underline;}
span.EmailStyle17
        {font-family:Arial;color:navy;}
 _filtered {margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {}
-->
</style>



<div class="Section1">

<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Tiger,</span></font></p> 

<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;"> &nbsp;</span></font></p> 

<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Firstly, I noticed you named your function
“open()” – I wouldn’t use that name, it is the name of
a Perl operator; In fact, you use Perl “open()” within your “open()”.</span></font></p> 

<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;"> &nbsp;</span></font></p> 

<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Secondly, the error message might be
indicating a simple syntax error in preceding code.&nbsp; Look for a missing
semi-colon, etc., in the code just before the error.</span></font></p> 

<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;"> &nbsp;</span></font></p> 

<p class="MsoNormal"><font color="navy" face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial; color: navy;">Alexander Danel</span></font></p> 

<div>

<div class="MsoNormal" style="text-align: center;" align="center"><font face="Times New Roman" size="3"><span style="font-size: 12pt;">

<hr tabindex="-1" align="center" width="100%" size="2">

</span></font></div>

<p class="MsoNormal"><b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;">From:</span></font></b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;">
chicago-talk-bounces+danel=speakeasy.net@pm.org
[mailto:chicago-talk-bounces+danel=speakeasy.net@pm.org] <b><span style="font-weight: bold;">On Behalf Of </span></b>tiger peng<br>
<b><span style="font-weight: bold;">Sent:</span></b> Monday, October 25, 2010
12:24 PM<br>
<b><span style="font-weight: bold;">To:</span></b> <a target="_blank" href="http://Chicago.pm">Chicago.pm</a>
 chatter<br>
<b><span style="font-weight: bold;">Subject:</span></b> Re: [Chicago-talk]
logging in and out files</span></font></p> 

</div>

<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size: 12pt;"> &nbsp;</span></font></p> 

<div>

<p class="MsoNormal"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">Weird, when I tested the module, with </span></font><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">open
FH, $filename; </span></font><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">with </span></font><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">use strict; It complain with
message: Bareword "FH" not allowed while "<span style="background: none repeat scroll 0% 0% yellow;">strict subs</span>" in use...&nbsp; </span></font></p> 

<div>

<p class="MsoNormal"><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> &nbsp;</span></font></p> 

</div>

<div>

<p class="MsoNormal"><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> &nbsp;</span></font></p> 

<div>

<div class="MsoNormal" style="text-align: center;" align="center"><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;">

<hr align="center" width="100%" size="1">

</span></font></div>

<p class="MsoNormal" style="margin-bottom: 12pt;"><b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;">From:</span></font></b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;"> 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</span></font></p> 

<div>

<div>

<p class="MsoNormal" style="margin-bottom: 12pt;"><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;">I tried out a working version below.
It works for $FH and FH, but not clear why.<br>
<br>
</span></font><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">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>
}</span></font></p> 

</div>

<div>

<p class="MsoNormal"><font face="Courier New" size="2"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> &nbsp;</span></font></p> 

<div>

<div class="MsoNormal" style="text-align: center;" align="center"><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;">

<hr align="center" width="100%" size="1">

</span></font></div>

<p class="MsoNormal"><b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma; font-weight: bold;">From:</span></font></b><font face="Tahoma" size="2"><span style="font-size: 10pt; font-family: Tahoma;"> imran javaid
&lt;imranjj@gmail.com&gt;<br>
<b><span style="font-weight: bold;">To:</span></b> <a rel="nofollow" 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>
</span></font><font face="Arial" size="2"><span style="font-size: 10pt; font-family: Arial;"><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>
&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><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>
&gt;&gt; <a target="_blank" href="http://mail.pm.org/mailman/listinfo/chicago-talk">http://mail.pm.org/mailman/listinfo/chicago-talk</a></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></span></font></p> 

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div></div>
</div></body></html>