Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > tie problem

Reply
Thread Tools

tie problem

 
 
Richard
Guest
Posts: n/a
 
      10-29-2003
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;
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      10-29-2003

http://www.velocityreviews.com/forums/(E-Mail Removed) (Richard) wrote:
> 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

--
"If a book is worth reading when you are six, * (E-Mail Removed)
it is worth reading when you are sixty." - C.S.Lewis
 
Reply With Quote
 
 
 
 
Richard Churchill
Guest
Posts: n/a
 
      10-29-2003
"Ben Morrow" <(E-Mail Removed)> wrote in message
news:bnov85$kqk$(E-Mail Removed)...
>
> (E-Mail Removed) (Richard) wrote:
> > 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
>
> --
> "If a book is worth reading when you are six, *

(E-Mail Removed)
> it is worth reading when you are sixty." - C.S.Lewis


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.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.532 / Virus Database: 326 - Release Date: 27/10/2003


 
Reply With Quote
 
Bart Lateur
Guest
Posts: n/a
 
      10-30-2003
Richard Churchill wrote:

> 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.


--
Bart.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
tie() with DB_File not tie()ing ? botfood Perl Misc 23 04-26-2006 01:59 AM
File::Tie problem (newbie ?) cmic Perl Misc 4 02-24-2006 07:41 AM
stringstream tie problem David Johnstone C++ 4 11-13-2003 07:34 PM
Tie a file handle to a variable Carlo Filippini Perl 1 10-02-2003 11:12 AM
Tie to change line in file Jonathan Weekes Perl 0 09-14-2003 02:24 PM



Advertisments