Occurs before $main::FH_text_W is initialized.my $FH_text_W = $main::FH_text_W;
A more traditional perl/OO way to do this would be to make the package "MyPkgDirectory::MyPkg" a true object/class, with a "new" method that initializes the object.
Then , in "main: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 $f +ilename for writing $!"; my $pkg = MyPkgDirectory::MyPkg::->new( $FH_text_W); $pkg->samplewrite(10, "foofoo");
"You're only given one little spark of madness. You mustn't lose it." - Robin Williams
In reply to Re: Globalize Filehandles and Visibility in Packages?
by NetWallah
in thread Globalize Filehandles and Visibility in Packages?
by smknjoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |