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

Hi people,

I had a Perl script working perfectly using CGI.pm, sucking info in from a form then dynamically creating funky pages for the user.

I tried to update this by incorporating a dbm File but this renders all print statements after the dbmopen statement useless.

If I comment the dbmopen statement from my code it will ..

If I do not comment it out it will...

This I can't explain

here's the code...

#!/apps/PERL5/bin/perl use CGI qw(:standard); $cgi = new CGI; print header; print "\nOne\n"; print "Two\n"; dbmopen(%dbm_New_Eng, "/apps/servicelist/SLNamesDBMs/srv_name_new_to_r +epresents", 0644) or die "Cannot open: $1\n\n"; print "Three\n"

Any advice on this matter would be greatly appreciated

Mark

Replies are listed 'Best First'.
Re: Conflict between CGI.pm & dbm Files?
by Ovid (Cardinal) on Sep 30, 2002 at 21:55 UTC

    My initial guess is that you have a permissions problem and your CGI code is running with your Web server's permissions and the file cannot be opened with those permissions. Check your Web server's error log for the message.

    Another thing you can do is send your fatal error message directly to the browser.

    #!/apps/PERL5/bin/perl -wT use CGI qw/ :standard /; use CGI::Carp qw/ fatalsToBrowser /; # remove for production use strict; print header, start_html, p( 'One' ); my $file = "/apps/servicelist/SLNamesDBMs/srv_name_new_to_represents"; dbmopen(%dbm_New_Eng, $file, 0644) or die "Cannot open ($file): $!"; print p( 'Two' ), end_html;

    Miscellaneous comments:

    • The error variable is dollar bang ($!), not dollar one ($1).
    • Many people may not recognize dbmopen as tie is usually used in place of it.
    • You may also want to review my CGI course to understand a few tweaks I made to your code.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      There is nothing in the servers error logs?

      How can I go about sending the fatal error message directly to the browser?

      Cheers,

      Mark

        Add:

        #!/apps/PERL5/bin/perl use CGI qw(:standard); use CGI::Carp qw/ fatalsToBrowser /; # remove for production use strict; $|=1; # do not buffer output ...

        This will turn off buffering for your CGI script and print everything directly so that you can see what your script is outputing. The output should appear in your browser.

        --
        hiseldl
        What time is it? It's Camel Time!