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

I have researched this question out on the web as well as I know how in several places (perlmonks, Orielly, etc.) but have found no answers.

Using ActivePerl with Apache web server on Windows ME operating system (home computer). I know, thats not the greatest situation but till I get linux thats what I am using. Am trying to write data out to a file that is input from a web page form thru GET and is passed into a %hash variable (%form_data) for parsing. Am able to print qq($name - $value <br><br>); and view the hash pairs on the web page as shown below. However, when I try to write them out to a file using:     print GUESTBOOK $form_data{'name'}  # for example (see below) nothing is actually written although the web page executes as shown below. Does anyone know if this is a problem with the Windows version of Perl or Apache or maybe I am doing something wrong AGAIN.

#----- Hash parse section shown below ---------------------- # Finally, we'll load the variables into an associative array # so we can use it when we need it. my %form_data; if($form_data{$name}) { $form_data{$name} .= "\t$value"; } else { $form_data{$name} = $value; } print qq($name = $value <br><br>); }
#------------------------------------------------- This is the web page output from above print qq statement plus other c +ode #-----------------------------------------------------------
name = me email = me@you.com city = boogerville location = XYZ web_url = www.me.you web_title = STUFFit comments = These are comments. Hi There. What'cha doin'? Your GuestBook Entry has been Submitted! Your guestbook entry has been successfully added to the guestbook. You + may need to click reload to view your guestbook entry.
#------------------------------------------------- # attempt to write data out to a file here. # doesn't work. nothing writes out. if($form_data{'email'}) { # if there's an email address, let's add it as a link print GUESTBOOK "<DD><I><B><A HREF=\"mailto:$form_data{'email +'}\"> $form_data{'name'}</A></B> - $form_data{'city'}, $form_data{'location'}</I>\n"; } else { # otherwise, just add their name print GUESTBOOK "<I><B>From:</B> $form_data{'name'}</I><BR>\n"; }

Edit kudra, 2002-08-31 Removed code tags around plaintext

# the above code does not put out any data to the file but it does run. Thanks, ljdennis@att.net

Replies are listed 'Best First'.
Re: Hash Parsing Problem
by tadman (Prior) on Aug 30, 2002 at 17:48 UTC
    You might want to check that the file GUESTBOOK is actually opened. Since you didn't post that bit of code, I'm presuming it should look something like this:
    open(GUESTBOOK, ">>", $guestbook) || die "Could not open guestbook\n";
    If your filehandle isn't open, you may be printing to nowhere.

    Further, where are you getting %form_data from? The code you posted shows you declaring it, then suddenly expecting things to exist by magic. Here's how you might do it:
    use CGI; my $cgi = CGI->new(); my %form_data = %{$cgi->Vars};
    Also, watch out! use strict. I think you're making a mistake when you do this:
    $form_data{$name}
    Don't you mean this?
    $form_data{name}
    With strict and warnings, the variable reference should cause a complaint, since $name is presumably undeclared.