Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Problems using DB_File on Windows (was: Windows/UNIX)

by perleager (Pilgrim)
on Apr 21, 2001 at 07:26 UTC ( [id://74385]=perlquestion: print w/replies, xml ) Need Help??

perleager has asked for the wisdom of the Perl Monks concerning the following question:

Hello:

I have a windows and a unix machine. The following code works on UNIX but not Windows. Any idea why? and what I could fix to make it work? Also can you give me any refference for where to learn about the diffrentiallity between programming PERL on the twho machines.

############ADD MEMBER FOR HOME.CGI sub addmember { $timerss = time; use DB_File; # optional; overrides default tie %add, "DB_File", "" or die "Can't open FILENAME: $!\n"; # o +pen database tie hash to db #account-keys time-values $add{$account} = "$timerss"; #REFRESH TIME untie %add; dbmclose %add; &whosonline; }


Thank you,
Anthony

2001-04-21 Edit by Corion : Changed title

Replies are listed 'Best First'.
Re: Windows/UNIX
by chromatic (Archbishop) on Apr 21, 2001 at 07:47 UTC
    perlport has some good information on things that don't work consistently between Perl platforms.

    Nothing in your code immediately stands out as Not Working. I would recommend you give us an exact error message when running under -w and strict for better answers.

Re: Windows/UNIX
by eejack (Hermit) on Apr 21, 2001 at 08:34 UTC
    Howdy perleager,

    I think windows perl does not come with DB_File capability. At least when I try to run your script I get this error: Can't locate DB_File.pm in @INC

    I tried to pull it down using ppm but no dice.

    You might want to look at the perlport page chromatic suggested under the part about standard modules. It suggests you might be able to use AnyDBM_File - which I am not familar with, but which appears to be functioning on my windows perl.

    EEjack

      eejack is correct, DB_File is mainly for Unix platforms.

      I'm guessing that is your main problem: use DB_File;. But, there are binaries out there in which include DB_File for a Win32 distribution by Gurusamy Sarathy. You can ftp the files here. Hope this helps a bit.
      AnyDBM_File will use its preference for a dbm. It will always find something though because it can fall back on SDBM_File which ships with Perl.

      However if keys or values go over 2K, that will cause data corruption. So don't use SDBM_File if you can avoid it.

      Also note that if you are using one dbm and then install another, AnyDBM_File will no longer know how to read any of the data files that you previously worked with. Caveat programmer.

Re: Windows/UNIX
by Chmrr (Vicar) on Apr 21, 2001 at 08:22 UTC

    As chomatic states, perlport might turn something up. A little more information might help, though. "Doesn't work" is fairly general -- for what value of "doesn't work"? Also, what version of perl -- and is it the same on both machines? The dbmclose looks vaguely suspect to me, as that construct is depreciated in all current perls.

    Update: FYI, the following code works fine for me under ActivePerl 5.6:

    use DB_File; tie %add, "DB_File", "foo.db" or die "Can't open FILENAME: $!\n"; $add{time} = time; untie %add;

    Adding the dbmclose doesn't change it, either. Because you didn't use dbmopen to open the database, it isn't needed. Nor should it ever be, because tie has replaced it. ;>

     
    perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://74385]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-03-19 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found