tie problem

Discussion in 'Perl Misc' started by Richard, Oct 29, 2003.

  1. Richard

    Richard Guest

    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;
     
    Richard, Oct 29, 2003
    #1
    1. Advertising

  2. Richard

    Ben Morrow Guest

    (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, *
    it is worth reading when you are sixty." - C.S.Lewis
     
    Ben Morrow, Oct 29, 2003
    #2
    1. Advertising

  3. "Ben Morrow" <> wrote in message
    news:bnov85$kqk$...
    >
    > (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, *


    > 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
     
    Richard Churchill, Oct 29, 2003
    #3
  4. Richard

    Bart Lateur Guest

    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.
     
    Bart Lateur, Oct 30, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonathan Weekes

    Tie to change line in file

    Jonathan Weekes, Sep 14, 2003, in forum: Perl
    Replies:
    0
    Views:
    498
    Jonathan Weekes
    Sep 14, 2003
  2. Carlo Filippini

    Tie a file handle to a variable

    Carlo Filippini, Sep 29, 2003, in forum: Perl
    Replies:
    1
    Views:
    449
  3. David Johnstone

    stringstream tie problem

    David Johnstone, Nov 13, 2003, in forum: C++
    Replies:
    4
    Views:
    489
    David Johnstone
    Nov 13, 2003
  4. cmic

    File::Tie problem (newbie ?)

    cmic, Feb 22, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    82
    Gunnar Hjalmarsson
    Feb 24, 2006
  5. botfood

    tie() with DB_File not tie()ing ?

    botfood, Apr 24, 2006, in forum: Perl Misc
    Replies:
    23
    Views:
    467
    botfood
    Apr 26, 2006
Loading...

Share This Page