newbie_77 has asked for the wisdom of the Perl Monks concerning the following question:

I posted an inquiry a couple of days ago regarding the behavior of Store_fd. I found out that this wasn't the problem. The thing is that I'm trying to serialize an object and I'm trying to do it with "Storable". I open up a file and when I write into it with store_fd it doesn't do it. I just found out that somehow a function that I am using is closing the file or redirecting the file descriptor in some manor. The following is an extract from my code to see if anybody can help me:
local *F; open (F, ">$file") || die "Error opening $file: $!\n"; my ($id, $obj); while (($id, $obj) = each %$all_instances) { my $class = ref($obj); my @attrs = $obj->get_attributes(@{$this-> get_attrs_for_class($class)}); ### I discovered that after this line of code, ### it either closes the file or redirects the ### file descriptor. my @array = ($class, $id, @attrs); Storable::store_fd (\@array, \*F); } close(F);

Replies are listed 'Best First'.
Re: Need a little help with file handles.
by btrott (Parson) on Jun 30, 2000 at 21:36 UTC
    You wrote:
    > ### I discovered that after this line of code, > ### it either closes the file or redirects the > ### file descriptor.
    Which line? The get_attributes line?

    How did you determine this? By checking the value of fileno? If not, you could check it like this:

    print "Before: ", fileno(F), "\n"; .... print "After: ", fileno(F), "\n";
    If the value changes, then your suspicion is correct. I don't think that the file has been closed, because I just tried that myself, and if the file were closed store_fd would die with the error "Not a valid file descriptor".