Hello, I am trying to get this save() sub to use sortRecordByDate() so when the records are written to the database file thery are already in correct order by date.
Thanks
Tim
################### save ##########################
#################### sortRecordByDate ####################
In the begining
Let us first assume that there was nothing to begin with.
Thanks
Tim
################### save ##########################
Code:
sub save{
my ($self)=@_;
my $fileName = $self->filename();
my $delimiter= $self->delimiter();
open ( FH, ">$fileName") || die "Unable to open $fileName. [$!] \n";
flock FH, $LOCK_EX;
print "[FileDB] Writing to File..\n" if ($self->debug());
foreach my $key (sort keys%{$self->{data}}){
print FH join($delimiter, @{$self->{data}{$key}}) ."\n";
}
flock FH, $LOCK_UN;
close FH;
return 1;
}
Code:
sub sortRecordByDate{
my ($hr1,$min1) = split(":",$a->[4]);
my ($hr2,$min2) = split(":",$b->[4]);
my $tstamp1 = timelocal(0,$min1,$hr1,$a->[2],$month2Num{$a->[1]},$a->[3] );
my $tstamp2 = timelocal(0,$min2,$hr2,$b->[2],$month2Num{$b->[1]},$b->[3] );
return $tstamp1 <=> $tstamp2;
}
In the begining
Let us first assume that there was nothing to begin with.