You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by silent <si...@gmail.com> on 2006/11/27 02:05:16 UTC
答复: why can't I get data from DBM in mod_perl
Thanks all, after I chown it to apache user and group it works!
And I also made operator precedences mistake in my script.
Thanks!
-----邮件原件-----
发件人: tomas@tuxteam.de [mailto:tomas@tuxteam.de]
发送时间: Friday, November 24, 2006 6:27 PM
收件人: silent
抄送: modperl@perl.apache.org
主题: Re: why can't I get data from DBM in mod_perl
-----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-----