perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@tuxteam.de
Subject Re: why can't I get data from DBM in mod_perl
Date Fri, 24 Nov 2006 10:27:09 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Nov 24, 2006 at 04:47:21PM +0800, silent wrote:
> Hi all,
> I need help with mod_perl:
> My ENV is redhat ES4 + apache2.0.59 + mod_perl2.
> 
> I wrote a small script:
> ####################
> package myconf;
> 
> use strict;
> use warnings;
> use DB_File;
[...]
> warn "data count:$#title\n";  ### but in error_log  it is -1
[..]

Seems the tie didn't work and now your hash is empty.

This ain't a modperl question :-)

You'll get exactly this behaviour when you can't write to the file
(because of permissions -- or just because the file is not there).

Watch this:

 | tomas@herr-turtur:~$ perl
 | use DB_File;
 | 
 | tie my %dbh, 'DB_File', "foobar" || die "Argh: $@";
 | $dbh{'one'}=1;
 | $dbh{'two'}=2;

Now foobar has some stuff in it.

 | tomas@herr-turtur:~$ sudo chown root.root foobar
 | tomas@herr-turtur:~$ ls -l foobar
 | -rw-r--r-- 1 root root 12288 2006-11-24 11:05 foobar

and now I can read (but not write) to foobar

 | tomas@herr-turtur:~$ perl
 | use DB_File;
 | 
 | tie my %dbh, 'DB_File', "foobar" || die "Argh: $@";
 | print join("\n", map("$_=>" . $dbh{$_}, sort(keys(%dbh)))), "\n";
 | 

Noting... %dbh is empty!

 | tomas@herr-turtur:~$ sudo chown tomas.users foobar

Now I can open foobar r/w

 | tomas@herr-turtur:~$ perl
 | use DB_File;
 | 
 | tie my %dbh, 'DB_File', "foobar" || die "Argh: $@";
 | print join("\n", map("$_=>" . $dbh{$_}, sort(keys(%dbh)))), "\n";
 | one=>1
 | two=>2

It works!

You can fine-tune the behaviour using some flags, like O_RDONLY and so
on.

HTH
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFZsj9Bcgs9XrR2kYRAvoYAJ9bq6TJd14aPjsLaQeS2JPSRC8dbgCffJEs
DiN34KDWAQgxnI0auU0CSK0=
=BlkD
-----END PGP SIGNATURE-----


Mime
View raw message