<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 <tigerpeng2001@yahoo.com><br><b><span style="font-weight: bold;">To:</span></b> Chicago.pm chatter <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<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> 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>}<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 <imranjj@gmail.com><br><b><span style="font-weight: bold;">To:</span></b> <a target="_blank" href="http://Chicago.pm">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></font><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 rel="nofollow" ymailto="mailto:tigerpeng2001@yahoo.com" target="_blank" href="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 rel="nofollow" ymailto="mailto:joshua.mcadams@gmail.com" target="_blank" href="mailto:joshua.mcadams@gmail.com">joshua.mcadams@gmail.com</a>><br>> To: <a rel="nofollow" target="_blank" href="http://Chicago.pm">Chicago.pm</a> chatter <<a rel="nofollow" ymailto="mailto:chicago-talk@pm.org" target="_blank" href="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><span><span>> <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>><br>> On Wed, Oct 20, 2010 at 9:55 AM, tiger peng <<a rel="nofollow" ymailto="mailto:tigerpeng2001@yahoo.com" target="_blank" href="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 rel="nofollow" ymailto="mailto:tigerpeng2001@yahoo.com" target="_blank" href="mailto:tigerpeng2001@yahoo.com">tigerpeng2001@yahoo.com</a>><br>>> To: Chicago.pm chatter <<a rel="nofollow"
ymailto="mailto:chicago-talk@pm.org" target="_blank" href="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 rel="nofollow" ymailto="mailto:Chicago-talk@pm.org" target="_blank"
href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br><span><span>>> <a target="_blank" href="http://mail.pm.org/mailman/listinfo/chicago-talk">http://mail.pm.org/mailman/listinfo/chicago-talk</a></span></span><br>>><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>><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>><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>