Alrighty.

I am attempting to create a persistant hash within MacPerl (520r4), but I
must be screwing something up somewhere.

The problem:
The hash is created/opened as expected, but after I quit MacPerl, and
relaunch it, I can't read back in the dbm file.  The string placed into $!
reads: 'Inappropriate file type or format' 

To make it generally more confusing, and harder to reproduce - this only
happens 1 in 3 times, and *never* happens when I apple-period cancel the
script.  It's only happening when I -quit- while the script is running.

Personally, I can remember not to quit, and to always apple-period.
Unfortunatly, this script is ultimately meant for other people, and telling
them to never quit the app for fear of data corruption doesn't seem like a
very good fix.  :)

I am thinking (though I most likely am way off base here) that something
isn't properly closing out the dbm flies on quit.   Reading through past
mailing list stuff brought up topics on garbage collection, and the END
brace.  I thought I found a fix:  But END doesn't seem to work the way I'd
expect either.  Error message:  # END failed -- cleanup aborted 

So, now I am stuck.
Any ideas as to what might be going on are very much appreciated.

Sample code below.


###############  start script
 
dbmopen(%hash, "hashfile", 0755) || &bail("Unable to open/create hashfile: $!");

END
{
   dbmclose (%hash) || MacPerl::Answer("Couldnt close hashfile: $!", "shit");
}

sub bail {
   my $msg = shift;
   MacPerl::Answer($msg, "Quit");

   # I never see this ::Answer, so I think dbmclose is working, though
   # I also am unsure if dmbclose really returns success/failure, either.
   dbmclose (%hash) || MacPerl::Answer("Couldnt close hashfile: $!", "shit");

   MacPerl::Quit(2);
}


foreach (keys %hash) { .... do something with the data }

############### end script


--
Mahlon Smith
InternetCDS
http://www.internetcds.com

Reply via email to