my $FH_text_W = $main::FH_text_W;
####
package MyPkgDirectory::MyPkg; # assumes MyPkgDirectory/MyPkg.pm
use strict;
use warnings;
...
sub new{
my ($classname,$fh) = @_;
die "File handle not specified" unless $fh;
return bless {HANDLE => $fh}, $classname;
}
sub samplewrite {
my ($self,$ver, $sheet) = @_;
....
print {$self->{HANDLE}} "SHEET $sheet\n"; # Need funny braces to un-confuse "print"
}
####
... # No Pre-declaration. the handle is now a local
open(my $FH_text_W, $wmode, $filename) or die "ERROR: cannot open $filename for writing $!";
my $pkg = MyPkgDirectory::MyPkg::->new( $FH_text_W);
$pkg->samplewrite(10, "foofoo");