Brethern

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.

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")}
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.

But under 5.004_04, setting

my $handle = *RPT;
leaves $handle undef, so it loses when it does the open (or the print).

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


In reply to Opening files in 5.004 and 5.8 by throop

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.