Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Strange DBM behavior

by Stamp_Guy (Monk)
on Jul 03, 2001 at 20:37 UTC ( #93575=perlquestion: print w/replies, xml ) Need Help??
Stamp_Guy has asked for the wisdom of the Perl Monks concerning the following question:

I've got a problem with the following DBM script I'm working on. I'm running on a server with perl version 5.003_02 + two suidperl security patches. I get the following error: No write permission to ndbm file at line 16. Instead of the typical two files that this script generates on my home computer, it generates one file called pricelist.db. I can't chmod it either. What's wrong???
#!/usr/bin/perl5 use CGI::Carp qw(fatalsToBrowser); use strict; open(PL, "pricelist.txt") || die "Can't open pricelist"; my @pl = <PL>; close(PL); my %PL = (); dbmopen(%PL, "pricelist", 0777) || die "Can't open pricelist DBM: $!"; for(@pl) { my @split = split /\|/; chomp($split[-1]); if (defined($PL{$split[1]})) { $PL{$split[1]} = "$PL{$split[1]}|$split[2],$split[3]"; } else { $PL{$split[1]} = "$split[2],$split[3]"; } } my $count = 0; print "There are ", scalar keys %PL, "items in the DB.\n"; dbmclose(%PL);

Replies are listed 'Best First'.
Re: Strange DBM behavior
by andreychek (Parson) on Jul 03, 2001 at 20:59 UTC
    This definitely sounds like a permissions issue as opposed to a Perl issue, but a little more information might be helpful.

    You mentioned about chmod'ing a file, so I'll assume you're using UNIX/Linux. You're using CGI::Carp, so I'll assume you're using this under a browser, and not running it by hand or via cron. Which probably means you're using Apache (since netcraft claim 62% of the net is using that anyway :-)

    It sounds like what you need to do is verify that the directory your db files are in are writable by the user which Apache is running as, which would often be 'apache' or 'nobody' on a UNIX-like system. Additionally, make sure the pricelist.db is writable by that same user. If it isn't, it would block you from being able to access that DB, such as what is happening right now. Since you are unable to chmod it, you may have to do it as root. If you don't have root access, just ask your admin to make those dirs/files writable by the Apache process.
Re: Strange DBM behavior
by Stamp_Guy (Monk) on Jul 03, 2001 at 21:18 UTC
    I did another test to see if I could read from it, but no such luck. Here's what I got:
    #!/usr/bin/perl5 use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); my $cgi = new CGI; use strict; my @scott = $cgi->param('scott'); print "Content-type: text/html\n\n"; my %PL; dbmopen(%PL, "pricelist", 0777) || die "Can't open pricelist DBM: $!"; foreach my $scott (@scott) { if ($scott ne "") { if (defined $PL{$scott}) { my @split = split(/\|/, $PL{$scott}); for(@split) { my ($description,$price) = split/,/; print "Scott: $scott\t$description\t$price\n"; } } else { print "Scott number $scott not found\n"; } } } dbmclose(%PL);
    Here's the error I get:
    Software error: Missing $ on loop variable at blah blah blah/ line 10.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://93575]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2017-09-23 06:55 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (272 votes). Check out past polls.