E
Eric
Hello,
Currently, our code is utilizing a database that is neither humanly
readable or writable. My task is to modify the existing code so that
the database is both. A sample of the code is below - in this
particular example, to request a mount point. (It does some other
stuff, such as incrementing/decrementing counts, etc., but that can be
ignored in relation to this request for assistance.)
I'm not looking for the solution in the posting (that wouldn't be any
fun ; what I am looking for is some initial direction on how I might
go about accomplishing this. There are no shortage of database related
core and CPAN modules. In particular, I was told to use the 'mySQL'
approach (if that means anything to anybody).
Anyone have an idea on how I might go about this task?
Thanks to advance to all that respond.
Eric
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
sub RequestMountPoint {
my $self = shift;
my $protocol = shift;
my $bldNum = shift;
my $mntPnt = undef;
my $mntDBfile = $self->Config->HomeDir()."/mntDBfile";
my $mntsDB = {};
unless (open SEMAPHORE, "> /tmp/mnt.lock") {
$self->Config->Env->ReleaseMach();
die "problem allocating semaphore";
}
flock SEMAPHORE, Fcntl::LOCK_EX;
tie( %$mntsDB, "MLDBM", $mountsDBFile, O_CREAT|O_RDWR, 0666,
$DB_File:B_BTREE );
my $mountPoint = $self->Config->MountPointCount();
for (my $label = 0; $label < $mountPoint; $label++){
$mntPnt = "mntpnt".$label;
unless (defined($mntsDB->{$mntPnt})){
$mntsDB->{$mntPnt} = {
BldNum => $bldNum,
Protocol => $protocol,
RefCnt => 1,
};
last;
}
if (($mntsDB->{$mntPnt}->{BldNum} == $bldNum) and
($mntsDB->{$mntPnt}->{Protocol} eq $protocol)) {
$mntsDB->{$mntPnt}->{RefCnt}++;
last;
}
$mntPnt = undef;
}
my $ref = $mntsDB->{$mntPnt}->{RefCnt};
untie(%$mntsDB);
close(SEMAPHORE);
return $mntPnt, $ref;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Currently, our code is utilizing a database that is neither humanly
readable or writable. My task is to modify the existing code so that
the database is both. A sample of the code is below - in this
particular example, to request a mount point. (It does some other
stuff, such as incrementing/decrementing counts, etc., but that can be
ignored in relation to this request for assistance.)
I'm not looking for the solution in the posting (that wouldn't be any
fun ; what I am looking for is some initial direction on how I might
go about accomplishing this. There are no shortage of database related
core and CPAN modules. In particular, I was told to use the 'mySQL'
approach (if that means anything to anybody).
Anyone have an idea on how I might go about this task?
Thanks to advance to all that respond.
Eric
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
sub RequestMountPoint {
my $self = shift;
my $protocol = shift;
my $bldNum = shift;
my $mntPnt = undef;
my $mntDBfile = $self->Config->HomeDir()."/mntDBfile";
my $mntsDB = {};
unless (open SEMAPHORE, "> /tmp/mnt.lock") {
$self->Config->Env->ReleaseMach();
die "problem allocating semaphore";
}
flock SEMAPHORE, Fcntl::LOCK_EX;
tie( %$mntsDB, "MLDBM", $mountsDBFile, O_CREAT|O_RDWR, 0666,
$DB_File:B_BTREE );
my $mountPoint = $self->Config->MountPointCount();
for (my $label = 0; $label < $mountPoint; $label++){
$mntPnt = "mntpnt".$label;
unless (defined($mntsDB->{$mntPnt})){
$mntsDB->{$mntPnt} = {
BldNum => $bldNum,
Protocol => $protocol,
RefCnt => 1,
};
last;
}
if (($mntsDB->{$mntPnt}->{BldNum} == $bldNum) and
($mntsDB->{$mntPnt}->{Protocol} eq $protocol)) {
$mntsDB->{$mntPnt}->{RefCnt}++;
last;
}
$mntPnt = undef;
}
my $ref = $mntsDB->{$mntPnt}->{RefCnt};
untie(%$mntsDB);
close(SEMAPHORE);
return $mntPnt, $ref;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^