Hi:
I'm somewhat new to Perl and am trying to create a DBM with 500k+
records. Unfortunately, MacPerl eventually gives an Out of Memory error
and shortly thereafter crashes the Mac, sometimes bringing up Macsbug,
othertimes just freezing the entire system.
So, 1) what am I doing wrong in the code below that is causing the error?
I thought once a hash was tied to a file, it would not need to allocate
memory to the hash. And 2), what can I do to stop the program when it
gets the memory error but before it crashes?
Thanks!
Joe
sub DoCust {
{
my $fname = 'unld03e';
open (INP, $fname) or die "File <$fname> not found. $!";
#open (ERR, ">cbss-cust-$fname.err");
}
use vars '%CAN_CUST'; #key = CAN, value = Customer Name
use Fcntl;
use NDBM_File;
tie %CAN_CUST, "NDBM_File", 'can_cust', O_RDWR|O_CREAT|O_EXCL, 0644;
%CAN_CUST = (); # clear existing hash/file
#CLEAR (%CAN_CUST); # doesn't seem to work
my $reccnt = 0;
while (<INP>) {
chomp;
$reccnt++;
$_ =~ s/\0/ /g; # convert nulls to blank ($A field)
my $cust_acct_no = substr($_, 0, 10);
my $customer_name = substr($_, 11, 28);
$customer_name =~ s/\s+$//;
$CAN_CUST{$cust_acct_no} = $customer_name;
} #end while
close (INP);
print scalar %CAN_CUST;
untie %CAN_CUST;
print "CBSS: Customer Name count: $reccnt\n";
return 1;
} #end sub
Joe M. Oglesby
[EMAIL PROTECTED]
http://jmo.OglesbyFamily.net
FAX: 425/740-9343
pager: 877/946-2253