Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: how to pass filehandle between module ?

by Athanasius (Archbishop)
on May 11, 2013 at 02:52 UTC ( [id://1033078]=note: print w/replies, xml ) Need Help??


in reply to how to pass filehandle between module ?

It is possible to do what you want by making TEST a package-scope variable within package openFile and then exporting it. (You would also need to export an openFile::close() subroutine to call in place of close (TEST).)

But this is a poor design. Much better to put all the file opening, writing, and closing routines together into a single package, e.g. package MyFile, and keep the details of the filehandle variable (in this case, MyFile::TEST) private to the package (i.e., unexported).

The general rule of modularisation is: Group related things together and keep independent things separate. In this case, opening and writing to the file are closely related activities and should be implemented within the same package.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1033078]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found