SPUG: Looking for a graceful way to deal with file handles and modules

jimfl jimfl at colltech.com
Tue Sep 28 17:59:24 CDT 1999


--On Tue, Sep 28, 1999 2:32 PM -0700 caseyt at metaip.checkpoint.com wrote:

     > Hi again Perl gurus and generally smart people,
     > 
     > I have a question about file handles and modules and how they can
     > get all mixed up. Here is what I have:
     > 
     > Main Script (many of these)
     > 	 Opens and writes to a file handle.
     > 
     > Perl Module (has all of the subroutines for all the main scripts)
     > 	 Also needs to write to the file.
     > 
     > The solutions I can think of are:
     > 
     > 1. Open and close the file handle every time I write to it.
     > 2. Have file handles open to the file in the module and the script
     > at the same time.
     > 
     > Is there some graceful way that I can reference an open filehandle
     > in my main script from the Perl module that has been called?
     > Something pretty like main::filehandle? 

use FileHandle;

my $fh = new FileHandle();
$fh->open $filename;
$line = <$fh>;

&SomeModule::do_something_interesting($fh);


--
Jim Flanagan          Collective Technologies
jimfl at colltech.com   http://www.colltech.com

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list