blahblahblah has asked for the wisdom of the Perl Monks concerning the following question:
instead of using our old idiom, which used a global filehandle name:if (-e $file && open (my $AFILE, "<$file")) { ...
Someone else recently tried my code, and they happened to have some logging turned on which broke the code. The logging overrides 'open' so that it can log files which have been opened. It looks like this:if (-e $file && open (AFILE, "<$file")) { ...
We use this logging very infrequently, but still it's useful sometimes so I don't want to break it. The easy solution is to go back to using the global filehandle, but then strict complains. Anyone have any good ideas as to how I can make this work? I found this old post, which talks about "tricks to create a reference to an anonymous filehandle" but doesn't go into detail. I'm wondering if I can create the filehandle first and then pass open a reference to it, or something like that. Thanks.sub open { my $filehandle = shift; # ... some logging happens here ... my $return; $return = CORE::open($filehandle,@_[0..$#_]); return $return; }
-Joe
|
|---|