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

Newbie here.
I'm appending a flat-file database with data from a form using the following code:
open(DATABASE, ">>/http01/cgi-bin/form/db/db.txt"); foreach $single_value (@form_values) { print DATABASE "$single_value|"; } close(DATABASE);
This works on the developement server but not the production server, which are supposedly setup exactly the same. I've double checked file permissions to make sure Perl can write to the file. The only thing I can think of is that there is a problem with the code. Any ideas??

Thanks

Replies are listed 'Best First'.
Re: appending a file
by suaveant (Parson) on Sep 27, 2001 at 23:13 UTC
    Always check your open for errors...
    open(DATABASE, ">>/http01/cgi-bin/form/db/db.txt") or die "could not o +pen db: $!"; foreach $single_value (@form_values) { print DATABASE "$single_value|"; } close(DATABASE);

                    - Ant
                    - Some of my best work - Fish Dinner

Re: appending a file
by CubicSpline (Friar) on Sep 27, 2001 at 23:11 UTC
    In what way does it not work? Nothing gets printed out to the file at all? Do you know for certain that that path exists? Are the two servers both Unixy or is one Windows? What do you get if you add in a print "$single_value|"; inside the loop? Does anything get printed there?

    Let us know some more details.

Re: appending a file
by arturo (Vicar) on Sep 27, 2001 at 23:17 UTC

    Change: open(DATABASE, ">>/http01/cgi-bin/form/db/db.txt");

    to something like :

    open(DATABASE, ">>/http01/cgi-bin/form/db/db.txt") or die "Can't open +db.txt for append: $!\n";

    That will give you an error message (as CubicSpline suggested, I'd bet it's that either your directory structure or permissions aren't set correctly). If this is a CGI script, you might want to put use CGI::Carp qw(fatalsToBrowser); at the top of your script (remove that line after the script goes into production, 'cos it could give valuable information to crackers). Adding that line will make sure you get to see the error message without poking around in the webserver's error logs.

    Of course, that surmise is only correct for some values of "doesn't work." =)

    HTH

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: appending a file
by mandog (Curate) on Sep 27, 2001 at 23:18 UTC
    You have the line
    open(DATABASE, ">>/http01/cgi-bin/form/db/db.txt")
    You might get few more clues with:
    my $fname="/http01/cgi-bin/form/db/db.txt" open(DATABASE,">>$fname") || die " $fname $!";
    You might try looking at the server logs.
    /var/log/apache/error.log
    is a common place to start looking for logs

    You might try posting how the "not working" manifests itself. No data in file? error message? bad data in the file?

    Hope this helps



    --mandog