tie problem

R

Richard

I am writing a script which accesses a DBM file using SDBM. The
program works but throws out a warning of: -

Argument "O_RDWR" isn't numeric in null operation

I've included Fcntl but that doesn't solve the problem. Does anyone
know why this is happening?


Thanks
Richard


use SDBM_File;
use Fcntl;

tie (%DB, 'SDBM_File', "fund.dbm",O_RDWR, 0644) or die "Couldn't find
file\n";

foreach $fund (keys %DB) {
print $fund;
}

untie %DB;
 
B

Ben Morrow

I am writing a script which accesses a DBM file using SDBM. The
program works but throws out a warning of: -

Argument "O_RDWR" isn't numeric in null operation

I've included Fcntl but that doesn't solve the problem. Does anyone
know why this is happening?

Try again like this:

#!/usr/bin/perl

use warnings;
use strict;
use SDBM_File;
use Fcntl;

tie (%DB, 'SDBM_File', "fund.dbm",O_RDWR, 0644) or die "Couldn't find
file\n";

Don't put \n on the end: it suppresses useful information about where
the error occurred.

Do include $!.

SDMB_File suggests you should usually use 0666 for the mode, as it is
modified by the umask.
foreach $fund (keys %DB) {
print $fund;
}

untie %DB;

You should probably use

untie %DB or die "failed to untie: $!";

here, as well.

If you get an error about O_RDWR, post again. 'use Fcntl' ought to
define it.

Ben
 
R

Richard Churchill

Ben Morrow said:
Try again like this:

#!/usr/bin/perl

use warnings;
use strict;


Don't put \n on the end: it suppresses useful information about where
the error occurred.

Do include $!.

SDMB_File suggests you should usually use 0666 for the mode, as it is
modified by the umask.


You should probably use

untie %DB or die "failed to untie: $!";

here, as well.

If you get an error about O_RDWR, post again. 'use Fcntl' ought to
define it.

Ben

Thanks, my problem turned out to be something different. I was using this
code inside a package and declaring the modules outside of the package, for
some reason Fcntl was not picked up correctly, but SDBM was. Once they were
both declared inside the package the warning went away.
 
B

Bart Lateur

Richard said:
I was using this
code inside a package and declaring the modules outside of the package, for
some reason Fcntl was not picked up correctly, but SDBM was.

The reason for the difference is that Fcntl uses a procedural interface,
so the names must be imported into your current package -- or you can
use fully qualified names, like Fcntl::O_RDWR; while tie uses an OO
interface, and import isn't necessary. The methods are still in a
completely separate package (class) whatever you do, and it's good that
way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top