------------------------------------------------
On Tue, 07 Oct 2003 15:22:34 -0400, Dan Anderson <[EMAIL PROTECTED]> wrote:
> I have a module that works with a couple of different file handles. Is
> it possible to hide them within an anonymous hash? {} (i.e. the objects
> data). Right now I have:
>
> if (condition_is_met()) {
> open("FILE","<file");
> }
>
> This is in the main body of my package (and thus, I assume, accessible
> by all functions). Is it better to use tighter encapsulation (i.e. a
> closure or throwing it into an anonymous hash) or just to leave it in
> the body?
>
Depending on your Perl version you can store filehandles to a lexical, like:
my $FILEHANDLE;
open($FILEHANDLE,...) or die ....;
And then presumably you can store your lexical whereever you want. It is my
understanding that when you reference it, it must be in a simple scalar, in which case
you will have to pull it out of your hash reference before using it. For example:
print $FILEHANDLE 'foo'; works but,
print $hashref->{'filehandle'} 'foo'; doesn't. but,
my $newlocation = $hashref->{'filehandle'};
print $newlocation 'foo'; should...
Gurus please correct me on this if I am wrong!!! And this depends on the way in which
you want to use it.
Again depending on your preference you could look at using the object classes for IO::
to handle all of this at which point you can store the object whereever you like, like
any other Perl object.
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]