Since you're using <$LOG> and not <LOG>, you could do the following:

use strict; use warnings; package MyPackage; sub open_file { my $fh; my $ok; require 5.006; # Require Perl 5.6 # Support both 2 and 3 arg version of open. if (@_ == 1) { $ok = open($fh, $_[0]); } else { $ok = open($fh, $_[0], $_[1]); } die("$!\n") unless $ok; return $fh; } 1;
use strict; use warnings; use MyPackage; our $LOG = open_file('log.txt'); # 'my' instead of 'our' also works while (<$LOG>) { print; }

Well, the logic to import open_file is missing, but that's easy. Check Exporter for details. Change open_file to MyPackage::open_file in the .pl until this is resolved.

Update: If you wanted to use <LOG>, how about:

use strict; use warnings; package MyPackage; sub open_file { local *fh; my $ok; # Support both 2 and 3 arg version of open. if (@_ == 1) { $ok = open(*fh, $_[0]); } else { require 5.006; # Require Perl 5.6 $ok = open(*fh, $_[0], $_[1]); } die("$!\n") unless $ok; return *fh; } 1;
use strict; use warnings; use MyPackage; *LOG = open_file('log.txt'); while (<LOG>) { print; }

In reply to Re: modules, exporting, and indirect filehandles by ikegami
in thread modules, exporting, and indirect filehandles by eff_i_g

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.