Re: database troubles



hOURS wrote:
I want to use PERL

Perl is the language.
perl is the interpreter.
PERL is a misspelling of one of the above.

to work with a database, but I can't seem to get PERL to open the databases
on my computer. I've been learning from Paul Hoffman's PERL for Dummies
(3rd edition). If I understand the book correctly, the code below should open
my database into an associative array, which I could then manipulate. e.g. In
the program below I try to print out the keys, print out an individual item, and
change an individual item. None of those 3 things happen though. The program
also doesn't die, nor do I get an error message. One thing it does execute for sure
is the last line - printing out a zero. That and the fact that when I "-w" the
program it tells me I'm using an uninitialized value in line 7 seem to indicate
that the database simply never opens.

No, that warning is not an indication that your DB never opened. It's
an indication that you're using an uninitialized variable. @A is not
the same as %A. If you had used strict, Perl would have told you that
you can't use @A without declaring it.

Why not?


By the way, I've tried various formulations of the second part of the
argument to dbmopen: with and without quotes, with and without file
extensions, having just the file name vs. specifying the whole path
(like C:/My Documents). Nothing works. But every time I run it, the
computer creates two files. Their names are the file name I put in the
argument to dbmopen, plus .dir for one, and .pag for the other.

The documentation for dbmopen says:
perldoc -f dbmopen
This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or
Berkeley DB file to a hash. HASH is the name of the
hash. (Unlike normal "open", the first argument is
not a filehandle, even though it looks like one).
DBNAME is the name of the database (without the .dir
or .pag extension if any). If the database does not
exist, it is created with protection specified by
MASK (as modified by the "umask").

So I'd guess it's likely that it can't find the file you're asking
about. If the file doesn't exist in the current working directory, I
would suggest you do put the full path in the open statement.


My guess is that PERL doesn't handle the types of databases I have.

Perl handles just about every database type imaginable, through the DBI
module and various DBD::* modules. dbmopen() is pretty well
depreciated

I have databases with the extensions .wdb, .dbf, and .mdb.

I have no idea what those are. Are those dbm, ndbm, sdbm, or Berkely
DB files?


Am I on the right track? What's going on here?

Don't really know. The first step would be to find out what kind of
databases you actually have, and then look for a module on CPAN
(http://search.cpan.org) that deals with those kinds of databases. The
second step would be to always `use strict;` and `use warnings;` in
your code.

Paul Lalli

.



Relevant Pages

  • PostgreSQL and Customer Database
    ... I've been working on both SQL and Perl for a while now, ... get them all onto an SQL database, and be able to keep track of sales, as ... the database available to customers and potential customers, ...
    (perl.beginners)
  • Ways of ensuring integers in the database are seen as numbers in perl?
    ... I'd like my database returned integers to look like integers to Perl but they currently don't until I add 0 to them. ... The reason for this is that adding 0 to a Perl scalar seems to persuade Perl the scalar is an integer. ... $num as returned from database: ...
    (perl.dbi.users)
  • Re: How to access MS Access from Perl?
    ... if you were to later migrate to MS SQL Server or Oracle ... minimize your load on the database server's compiled procedure cache. ... On the other hand, if startup time for your perl script is an issue, and ... slightly preferable to the bulkier DBI + DBD::ODBC. ...
    (comp.lang.perl)
  • Re: Attempted Simultaneous Access causes "Could not lock file"
    ... storing it in my MSAccess database. ... I just wrote another test perl program and pasted in the massive SELECT ... >> I can have multiple perl programs writing to the database, ... > It probably needs exclusive access to the entire Table if it's modifying ...
    (microsoft.public.access.tablesdbdesign)
  • Re: LAMP - Program Design with Perl
    ... > information and queries the MySQL database. ... > Maybe there are Perl modules to faciliate this kind of task? ... so I think it worthwhile to second Anno's suggestion on this method (eg. ... Aside from the hint about dispatch tables, ...
    (comp.lang.perl.misc)