B
Bill H
I am using the following 2 subroutines to load an array from a file and
save it. The LoadDataFile routine works correctly, but the SaveDataFile
routine only saves the last item in the array. The file that is read
from is straight text in the format of:
ITEM1\tVALUE1
ITEM2\tVALUE2
etc. The \t is a tab.
I call the LoadDataFile with this:
%myarray = &LoadDataFile("this is the file name");
and it loads the %myarray with the correct values.
I call the SaveDataFile with this:
&SaveDataFile("this is the filename",%myarray);
But it only saves the last entry. Am I doing somethign wrong in the
call or the SaveDataFile routine?
Here are the routines:
sub LoadDataFile
{
my $filename = shift;
my $temp = "";
my @dbf = ();
my %ldf_dbf = ();
open(LDF_LPFILE,$filename);
flock(LDF_LPFILE,2);
@LDF_LPFILE = <LDF_LPFILE>;
close(LDF_LPFILE);
foreach $temp (@LDF_LPFILE)
{
chop $temp;
@dbf = split(/\t/,$temp);
$ldf_dbf{$dbf[0]} = $dbf[1];
}
return (%ldf_dbf);
}
sub SaveDataFile
{
my $filename = shift;
my %this_dbf = shift;
my $temp = "";
open(LDF_LPFILE,">$filename");
flock(LDF_LPFILE,2);
foreach $temp (keys(%this_dbf))
{
print LDF_LPFILE "$temp\t$this_dbf{$temp}\n";
}
close(LDF_LPFILE);
return;
}
Any help is appreciated
Bill H
save it. The LoadDataFile routine works correctly, but the SaveDataFile
routine only saves the last item in the array. The file that is read
from is straight text in the format of:
ITEM1\tVALUE1
ITEM2\tVALUE2
etc. The \t is a tab.
I call the LoadDataFile with this:
%myarray = &LoadDataFile("this is the file name");
and it loads the %myarray with the correct values.
I call the SaveDataFile with this:
&SaveDataFile("this is the filename",%myarray);
But it only saves the last entry. Am I doing somethign wrong in the
call or the SaveDataFile routine?
Here are the routines:
sub LoadDataFile
{
my $filename = shift;
my $temp = "";
my @dbf = ();
my %ldf_dbf = ();
open(LDF_LPFILE,$filename);
flock(LDF_LPFILE,2);
@LDF_LPFILE = <LDF_LPFILE>;
close(LDF_LPFILE);
foreach $temp (@LDF_LPFILE)
{
chop $temp;
@dbf = split(/\t/,$temp);
$ldf_dbf{$dbf[0]} = $dbf[1];
}
return (%ldf_dbf);
}
sub SaveDataFile
{
my $filename = shift;
my %this_dbf = shift;
my $temp = "";
open(LDF_LPFILE,">$filename");
flock(LDF_LPFILE,2);
foreach $temp (keys(%this_dbf))
{
print LDF_LPFILE "$temp\t$this_dbf{$temp}\n";
}
close(LDF_LPFILE);
return;
}
Any help is appreciated
Bill H