For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2005 > tie DB_File flags









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author tie DB_File flags
Ken Gillett

2005-01-24, 8:55 pm

Information about these has proved hard to come by, but having
ascertained what I need to use I find another problem. I want to
calculate the flags to use beforehand, but if I try

tie %$dbm, "DB_File", $dbf, $dbflags, $mode, $DB_HASH;

even though $dbflags contains O_RDONLY I get the following error:=

Argument "O_RDONLY" isn't numeric in subroutine entry at
/usr/lib/perl5/5.8.6/i686-linux/DB_File.pm

This is caused by using the variable for the flags and if I replace
that with the actual string (no quotes) it works fine, so it's happy
with $dbf and $mode.

I'm using 5.8.6, but the problem also exists with 5.8.5 at least.

Can anyone suggest how I can get around this and use a variable for the
flags?



Ken G i l l e t t

_/_/_/_/_/_/_/_/_/

Jenda Krynicky

2005-01-26, 8:55 am

From: Ken Gillett <ken@ukgb.net>
> Information about these has proved hard to come by, but having
> ascertained what I need to use I find another problem. I want to
> calculate the flags to use beforehand, but if I try
>
> tie %$dbm, "DB_File", $dbf, $dbflags, $mode, $DB_HASH;
>
> even though $dbflags contains O_RDONLY I get the following error:=
>
> Argument "O_RDONLY" isn't numeric in subroutine entry at
> /usr/lib/perl5/5.8.6/i686-linux/DB_File.pm
>
> This is caused by using the variable for the flags and if I replace
> that with the actual string (no quotes) it works fine, so it's happy
> with $dbf and $mode.
>
> I'm using 5.8.6, but the problem also exists with 5.8.5 at least.
>
> Can anyone suggest how I can get around this and use a variable for
> the flags?


Show us the code!

Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

Marcello

2005-01-26, 3:56 pm

Ken Gillett ha scritto:
> Information about these has proved hard to come by, but having
> ascertained what I need to use I find another problem. I want to
> calculate the flags to use beforehand, but if I try
>
> tie %$dbm, "DB_File", $dbf, $dbflags, $mode, $DB_HASH;
>
> even though $dbflags contains O_RDONLY I get the following error:=
>
> Argument "O_RDONLY" isn't numeric in subroutine entry at
> /usr/lib/perl5/5.8.6/i686-linux/DB_File.pm


You are passing the string "O_RDONLY" to the subroutine, no the value of
O_RDONLY.

Maybe this works (untested):

<code>
$dbflags = O_RDONLY;
tie %$dbm, "DB_File", $dbf, $dbflags, $mode, $DB_HASH;
</code>

Marcello

>
> This is caused by using the variable for the flags and if I replace that
> with the actual string (no quotes) it works fine, so it's happy with
> $dbf and $mode.
>
> I'm using 5.8.6, but the problem also exists with 5.8.5 at least.
>
> Can anyone suggest how I can get around this and use a variable for the
> flags?
>
>
>
> Ken G i l l e t t
>
> _/_/_/_/_/_/_/_/_/
>
>


Ken Gillett

2005-01-28, 3:57 pm

On 26 Jan 2005, at 14:47, Marcello wrote:

> Ken Gillett ha scritto:
>
> You are passing the string "O_RDONLY" to the subroutine, no the value
> of O_RDONLY.
>
> Maybe this works (untested):
>
> <code>
> $dbflags = O_RDONLY;


Because PERL wouldn't let me. BUT, I just tried it again and it didn't
complain and the 'tie' worked perfectly, even when using
O_RDWR|O_CREAT|O_TRUNC. :-)

> tie %$dbm, "DB_File", $dbf, $dbflags, $mode, $DB_HASH;
> </code>


In the meantime since first noticing the problem I have done some
extensive re-writing of my code, so whatever I had that was causing the
problem has obviously been corrected (without me knowing what it was).
Anyway, the important point is that it now works as expected, so at
least my expectations were correct.

Thanks.



Ken G i l l e t t

_/_/_/_/_/_/_/_/_/

Jenda Krynicky

2005-01-28, 3:57 pm

From: Ken Gillett <ken@ukgb.net>
Subject: Re: tie DB_File flags
Date sent: Fri, 28 Jan 2005 11:59:52 +0000
To: Marcello <m.romani@spinsoft.it>

> On 26 Jan 2005, at 14:47, Marcello wrote:
>
>
> Because PERL wouldn't let me. BUT, I just tried it again and it didn't
> complain and the 'tie' worked perfectly, even when using
> O_RDWR|O_CREAT|O_TRUNC. :-)


I guess the constants were not imported into the main namespace. Any
chance you had something like

use DB_File ();

in the code? That way the constants would not be imported.

Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com