Home > Archive > PERL Beginners > January 2008 > file.db VS filedb
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]
|
|
|
| when i "use DB_File" the files produced lack a dot in their title, eg.
dbmopen %email, email.db, 0666;
manipulates a file who's directory entry is actually emaildb
MORE IMPORTANTLY, perl will not access a database outside of the same =20
directory as the script -- it pulls a blank hash. without being able =20
to include any functional path in the filenames, i can't even call the =20
script with a soft link...i have to use a shell script to cd first
that is ridiculous and i presume a bug that may have been fixed =20
somewhere?
perl 5.8.8 on fedora 7
| |
| John W. Krahn 2008-01-28, 7:11 pm |
| MK wrote:
> when i "use DB_File" the files produced lack a dot in their title, eg.
>
> dbmopen %email, email.db, 0666;
>
> manipulates a file who's directory entry is actually emaildb
>
> MORE IMPORTANTLY, perl will not access a database outside of the same
> directory as the script -- it pulls a blank hash. without being able to
> include any functional path in the filenames, i can't even call the
> script with a soft link...i have to use a shell script to cd first
>
> that is ridiculous and i presume a bug that may have been fixed somewhere?
>
> perl 5.8.8 on fedora 7
Put these two lines at the top of your program:
use warnings;
use strict;
And perl will tell you that you are concatenating two barewords.
email.db is tranlated by perl as 'email' . 'db' and there is no "dot" in
the concatenation of those two strings.
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
| |
| Gunnar Hjalmarsson 2008-01-28, 7:11 pm |
| MK wrote:
> when i "use DB_File" the files produced lack a dot in their title, eg.
>
> dbmopen %email, email.db, 0666;
>
> manipulates a file who's directory entry is actually emaildb
Please enable strictures and warnings!!
$ cat test.pl
#!/usr/bin/perl
use strict;
use warnings;
use DB_File;
dbmopen my %email, email.db, 0666;
$ ./test.pl
Bareword "email" not allowed while "strict subs" in use at ./test.pl line 5.
Bareword "db" not allowed while "strict subs" in use at ./test.pl line 5.
Execution of ./test.pl aborted due to compilation errors.
$
> MORE IMPORTANTLY, perl will not access a database outside of the same
> directory as the script -- it pulls a blank hash. without being able to
> include any functional path in the filenames, i can't even call the
> script with a soft link...i have to use a shell script to cd first
>
> that is ridiculous and i presume a bug that may have been fixed somewhere?
Talking about a "bug", based on that reasoning, _that_ is ridiculous.
Of course Perl will access a database in some other directory, if you
state the correct path to that directory.
dbmopen my %email, '/path/to/email.db', 0644
or die $!;
As a side note, there is a chdir() function in Perl.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Jenda Krynicky 2008-01-28, 7:11 pm |
| From: MK <halfcountplus@intergate.com>
> when i "use DB_File" the files produced lack a dot in their title, eg.
>
> dbmopen %email, email.db, 0666;
>
> manipulates a file who's directory entry is actually emaildb
If you do
use strict;
use warnings;
as you should it does not. It reports an error. And apparently
rightly so.
> MORE IMPORTANTLY, perl will not access a database outside of the same
> directory as the script -- it pulls a blank hash. without being able
> to include any functional path in the filenames, i can't even call the
> script with a soft link...i have to use a shell script to cd first
>
> that is ridiculous and i presume a bug that may have been fixed
> somewhere?
If you want to include a string literal in your script enclose it in
quotes. In this case it doesn't matter whether you use single or
double quotes:
dbmopen %email, 'email.db', 0666;
or
dbmopen %email, "email.db", 0666;
What happened was that Perl assumed that you want to join (the dot
operator) two unquoted words ... without 'use strict' you are allowed
to omit quotes around words like this:
$variable = Hello;
but you should NEVER EVER do that. The catch is that there is no
telling whether that should assign to the $variable the string
"Hello" or the results of calling the Hello subroutine. What it does
depends on the existence of such subroutine.
The next problem is that
use DB_File;
and
dbmopen ...
are not related at all. There is an old interface to one (hard to say
which) DBM file format via the builtin dbmopen function and there are
several different modules for different formats of on-disk-hashes
with their own interfaces. If you read the documentation of DB_File,
you could see that the way to tie a hash to a DB_File compatible file
is definitely not dbmopen().
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
| |
| Gunnar Hjalmarsson 2008-01-28, 10:08 pm |
| Jenda Krynicky wrote:
> The next problem is that
> use DB_File;
> and
> dbmopen ...
> are not related at all.
Why not? If you read "perldoc dbmopen", you even find an example call of
dbmopen() preceeded by "use DB_File".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Gunnar Hjalmarsson 2008-01-28, 10:08 pm |
| Gunnar Hjalmarsson wrote:
>
> Why not? If you read "perldoc dbmopen", ...
I meant "perldoc -f dbmopen".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
|
| you know gunnar i would swear on my mothers grave that i tried using =20
both "" and '' in this and it still would not work, otherwise i really =20
really really would not have cried wolf...but in all honesty it does =20
work now, so there's egg on my face
however, my connection of "dbmopen" with "DB_File" is straight out of =20
the 1st Perl Cookbook, but "tie" from the DB_File man doesn't seem much =20
different, nb. they both produce
Global symbol "%email" requires explicit package name at =20
/usr/local/bin/AddressBook line 6.
even with
tie %email, "DB_File", 'email.db';
as long as use warnings/use strict is enabled (otherwise it's fine).
To anyone's knowledge is there somewhere/one who has connected these =20
strict warning messages to specific meanings in context? (they would =20
seem very useful if that is the case, otherwise i cannot imagine what =20
"requires explicit package name" could mean beyond the supplied =20
"DB_File")
| |
| Gunnar Hjalmarsson 2008-01-29, 4:16 am |
| MK wrote:
> you know gunnar i would swear on my mothers grave that i tried using
> both "" and '' in this and it still would not work, otherwise i really
> really really would not have cried wolf...but in all honesty it does
> work now, so there's egg on my face
Okay... ;-)
> however, my connection of "dbmopen" with "DB_File" is straight out of
> the 1st Perl Cookbook, but "tie" from the DB_File man doesn't seem much
> different, nb. they both produce
>
> Global symbol "%email" requires explicit package name at
> /usr/local/bin/AddressBook line 6.
>
> even with
> tie %email, "DB_File", 'email.db';
>
> as long as use warnings/use strict is enabled (otherwise it's fine).
"use strict;" means that variables should be declared, so
tie my %email, "DB_File", 'email.db';
--------^^
> To anyone's knowledge is there somewhere/one who has connected these
> strict warning messages to specific meanings in context? (they would
> seem very useful if that is the case, otherwise i cannot imagine what
> "requires explicit package name" could mean beyond the supplied "DB_File")
Literally it suggests this:
tie %main::email, "DB_File", 'email.db';
---------^^^^^^
It's not the best worded error message in Perl...
Suggested reading: http://perl.plover.com/FAQs/Namespaces.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Jenda Krynicky 2008-01-29, 8:13 am |
| From: Gunnar Hjalmarsson <noreply@gunnar.cc>
> Jenda Krynicky wrote:
>
> Why not? If you read "perldoc dbmopen", you even find an example call of
> dbmopen() preceeded by "use DB_File".
Hmmmm, looks like I should reread perlfunc and find out what
functions that used to be deprecated were changed instead.
Thanks, 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
|
|
|
|
|