Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Well after staying up all night studying for a psychology final later this morning, I decided to take a meditative break and bang out a small script. Unexpected aggravation ensued! Perhaps my sleepy eyes overlook something? First, the code, short explanation follows:
sub DisplayPollResults { my $poll_results_dbase = POLL_DATA_LOCATION . "/polldbase.db"; dbmopen( my %DBASE, $poll_results_dbase, 0644 ) || print "Error opening $poll_results_dbase: $!"; ++$DBASE{ $q->param( 'poll' ) }; print $q->header( 'text/html' ), $q->start_html( -title => 'Poll Results', -style => {'src' => '/styles/style.css'} ), $q->hr, $q->p( "Hello " . $q->remote_host() . "! Thanks for your vote.<br +>" ), $q->p( $DBASE{ $q->param( 'poll' ) } ), $q->p( "You voted for: " . $q->param( 'poll' ) . "<br>" ), $q->table( map{ $q->Tr( $q->td( $_ . " -> " . $DBASE{$_} ) ) } sor +t keys %DBASE ), $q->hr, $q->a( {-href => $q->referer }, "Back" ); $q->end_html; dbmclose( %DBASE ); }

The strangeness lies in the fact that I cant ++$DBASE( value ); the mapping of %DBASE properly displays the keys and corresponding values - but I can't update the dern values! The devil's in the details - please exorcise him for me!

~Lacertus

Replies are listed 'Best First'.
Re: DBM Value++ In CGI
by cbro (Pilgrim) on May 13, 2003 at 13:07 UTC
    I don't work with DB files, so I tried something similar. I passed a CGI param and then did ++$HASH{ $p->param('box')} and it worked. That was even with using string values inside the hash. So, again, pardon my ignorance with DB files, but can you maybe not change the values in the way that you are trying because of the 0644 permissions. That is rw-r--r, and maybe the Perl script is not running as you... Just an idea,
    Chris
Re: DBM Value++ In CGI
by cbro (Pilgrim) on May 13, 2003 at 13:18 UTC
    I decided to break out the textbooks...Black Book and Perl In A Nutshell.

    Both of them are very quick when discussing dbmopen and dbmclose, but at the same time...both books say this, "If you don't have write access to the DBM file, you can only read the hash variables, not set them."
    Both books barely even discuss the functions, but take time to make that same point. Maybe it was how you opened the DB file, or it may just be your actual privileges on the file itself.
    I wish I worked with DBM files so I could provide a guaranteed answer, but permissions may very well be the problem.
Re: DBM Value++ In CGI
by Anonymous Monk on May 13, 2003 at 12:10 UTC
    My exhaustion shows in the fact I forgot to log in! Well, thanks for any help.

    ~Lacertus