<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
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
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=blue>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Tiger,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;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()”.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Secondly, the error message might be
indicating a simple syntax error in preceding code. Look for a missing
semi-colon, etc., in the code just before the error.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Alexander Danel<o:p></o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;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> <st1:PersonName w:st="on">Chicago.pm
chatter</st1:PersonName><br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [Chicago-talk]
logging in and out files</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
<div>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Weird, when I tested the module, with </span></font><font
size=2 face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"'>open
FH, $filename; </span></font><font size=2 face=Arial><span style='font-size:
10.0pt;font-family:Arial'>with </span></font><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>use strict; It complain with
message: Bareword "FH" not allowed while "<span
style='background:yellow'>strict subs</span>" in use... <o:p></o:p></span></font></p>
<div>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p> </o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
<hr size=1 width="100%" align=center>
</span></font></div>
<p class=MsoNormal style='margin-bottom:12.0pt'><b><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma;font-weight:bold'>From:</span></font></b><font
size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> tiger
peng <tigerpeng2001@yahoo.com><br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">Chicago.pm
chatter</st1:PersonName> <chicago-talk@pm.org><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><o:p></o:p></p>
<div>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><font size=2 face=Arial><span
style='font-size:10.0pt;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 size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'>sub open{<br>
my ($package, $file, $line_number) = caller();<br>
my $fullpath = Cwd::abs_path($file);<br>
my $host = hostname();<br>
_open_log({host=>hostname(),<br>
script=>Cwd::abs_path($file),<br>
file=>$_[1],<br>
}<br>
);<br>
if ($_[0]) {<br>
no strict 'refs';<br>
CORE::open("::$_[0]", $_[1]) or die
"Cannot open $_[1]: $!\n";<br>
} else {<br>
CORE::open($_[0], $_[1]) or die "Cannot
open $_[1]: $!\n";<br>
}<br>
}<o:p></o:p></span></font></p>
</div>
<div>
<p class=MsoNormal><font size=2 face="Courier New"><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
<hr size=1 width="100%" align=center>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> imran javaid
<imranjj@gmail.com><br>
<b><span style='font-weight:bold'>To:</span></b> <a href="http://Chicago.pm"
target="_blank">Chicago.pm</a> chatter <chicago-talk@pm.org><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 size=2 face=Arial><span style='font-size:10.0pt;font-family:
Arial'><br>
This might get you somewhere:<br>
<br>
use strict;<br>
use Symbol;<br>
<br>
sub myopen {<br>
if (ref(\$_[0]) eq 'SCALAR') {<br>
open ($_[0], $_[1]);<br>
} else {<br>
my $in = qualify_to_ref($_[0]);<br>
open($in, $_[1]);<br>
}<br>
}<br>
<br>
myopen(*FILE, ">file.txt") or die $!;<br>
print FILE "testing\n";<br>
myopen(my $FILE2, ">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 <<a
href="mailto:tigerpeng2001@yahoo.com" target="_blank"
ymailto="mailto:tigerpeng2001@yahoo.com">tigerpeng2001@yahoo.com</a>> wrote:<br>
> Thanks, it looks a good tool and I will try it later.<br>
><br>
> But my problem now is how to pass in and back the FH.<br>
><br>
> It complains with error message:<br>
> Can't use string ("FH") as a symbol ref while "strict
refs" in use at<br>
> /my/lib/myLogger.pm ...<br>
><br>
> When I let it do not complain with "no strict 'refs';", it does
not complain<br>
> but FH seems not opened or not passed back, as the caller read nothing
out.<br>
><br>
> ________________________________<br>
> From: Joshua <<a href="mailto:joshua.mcadams@gmail.com" target="_blank"
ymailto="mailto:joshua.mcadams@gmail.com">joshua.mcadams@gmail.com</a>><br>
> To: <a href="http://Chicago.pm" target="_blank">Chicago.pm</a> chatter <<a
href="mailto:chicago-talk@pm.org" target="_blank"
ymailto="mailto:chicago-talk@pm.org">chicago-talk@pm.org</a>><br>
> Sent: Wed, October 20, 2010 3:29:53 PM<br>
> Subject: Re: [Chicago-talk] logging in and out files<br>
><br>
> I haven't done this myself before, but it looks like some folks have<br>
> and have put their work on CPAN:<br>
> <a href="http://search.cpan.org/%7Ecwest/ex-override-1.1/override.pm"
target="_blank">http://search.cpan.org/%7Ecwest/ex-override-1.1/override.pm</a><br>
><br>
> On Wed, Oct 20, 2010 at 9:55 AM, tiger peng <<a
href="mailto:tigerpeng2001@yahoo.com" target="_blank"
ymailto="mailto:tigerpeng2001@yahoo.com">tigerpeng2001@yahoo.com</a>> wrote:<br>
>> I wrapped the open as below, and it works for the open $fh, $file but
not<br>
>> open FH, $file.<br>
>><br>
>> As I need to apply the wrapping open function to lots of old script, I<br>
>> prefer only add one line: use myLoger 'open'; into the scripts<br>
>><br>
>> Is there any suggestion?<br>
>><br>
>> sub open{<br>
>> my ($package, $file, $line_number) = caller();<br>
>> my $fullpath = Cwd::abs_path($file);<br>
>> my $host = hostname();<br>
>> _open_log({host=>hostname(),<br>
>>
script=>Cwd::abs_path($file),<br>
>>
file=>$_[1],<br>
>>
}<br>
>>
);<br>
>> CORE::open(shift, shift) or die "Cannot open :
$!\n";<br>
>> }<br>
>><br>
>> sub _open_log {<br>
>> ...<br>
>> }<br>
>><br>
>><br>
>> ________________________________<br>
>> From: tiger peng <<a href="mailto:tigerpeng2001@yahoo.com"
target="_blank" ymailto="mailto:tigerpeng2001@yahoo.com">tigerpeng2001@yahoo.com</a>><br>
>> To: <st1:PersonName w:st="on">Chicago.pm chatter</st1:PersonName> <<a
href="mailto:chicago-talk@pm.org" target="_blank"
ymailto="mailto:chicago-talk@pm.org">chicago-talk@pm.org</a>><br>
>> Sent: Tue, October 19, 2010 11:41:10 AM<br>
>> Subject: [Chicago-talk] logging in and out files<br>
>><br>
>> Hello all,<br>
>><br>
>> Does anyone have the experience on tracing input/output files used by
Perl<br>
>> script?<br>
>><br>
>> I am think if there is anyway to over write the build-in open
function, so<br>
>> the new open function can log the file name, IO type (R, W, or RW), as<br>
>> well<br>
>> as the open/close timestamp. Any suggestion is highly appreciated.<br>
>><br>
>> Thanks,<br>
>> Tiger<br>
>><br>
>> _______________________________________________<br>
>> Chicago-talk mailing list<br>
>> <a href="mailto:Chicago-talk@pm.org" target="_blank"
ymailto="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
>> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk"
target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
>><br>
> _______________________________________________<br>
> Chicago-talk mailing list<br>
> <a href="mailto:Chicago-talk@pm.org" target="_blank"
ymailto="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
><br>
> _______________________________________________<br>
> Chicago-talk mailing list<br>
> <a href="mailto:Chicago-talk@pm.org" target="_blank"
ymailto="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
><br>
_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org" target="_blank"
ymailto="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><o:p></o:p></span></font></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>