throop has asked for the wisdom of the Perl Monks concerning the following question:
I have existing code, much of it going back to Perl 4.?. I now need to run both on systems running 5.004_04 and 5.8. Existing code (which didn't use strict) used a string for a file handle.
Coming up to 5.8, this gave various scoldings when I use strict;. Changing 'local' to 'my' and 'RPT' to *RPT seemed to fix the problem.sub printSumpn{ local($handle, file) = ('RPT', '/tmp/report.txt'); myOpen($handle, $file); print $handle "hello world\n"; close($handle)} sub myOpen{ local($handle, $file) =@_; # ...do some logging and sanity checking... open($handle, ">$file")}
But under 5.004_04, setting
leaves $handle undef, so it loses when it does the open (or the print).my $handle = *RPT;
I want to set $handle equal to a filehandle, and be able to pass $handle to a file-opening subroutine, to print, and to close. I want to do this in a way that doesn't violate strict. And in a way that works under both 5.004_04 and 5.8.
Can I do that?
thanks
throop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Opening files in 5.004 and 5.8
by gaal (Parson) on May 11, 2007 at 21:27 UTC | |
|
Re: Opening files in 5.004 and 5.8
by grinder (Bishop) on May 12, 2007 at 15:24 UTC | |
by educated_foo (Vicar) on May 12, 2007 at 17:35 UTC | |
by gaal (Parson) on May 12, 2007 at 18:48 UTC |