On 08/26/2006 10:32 AM, Joel Alvo wrote:
Hi. I have some perl script attached that does not
return anything when I click the link "see what others
have to say". [...]
I didn't execute your script, but this part intrigued me:
sub create_comments_page {
my (%mail, $email, $name, $comments);
tie(%mail, "SDBM_File", "c09ex3", O_RDONLY, 0)
or die "Error opening c09ex3. $!, stopped";
$mail{$email} = "$name|$comments";
untie(%mail);
You open c09ex3 read-only, but you then attempt to write to
it. Why?
At this point, you should want to read the data from the DB
file, so you would naturally save the contents of %mail to
another hash before closing the file with untie():
my %mailcopy = %mail
untie(%mail);
The following part is also wrong:
print "<H2>What other coffee lovers say \n";
print "about our coffees:</H2>\n";
foreach ($mail{$email}) {
print "$name said $comments\n";
}
The reason this 'foreach' is not doing very much, is probably
that the hash %mail is now undefined because the file it was
tied to is closed.
Additionally, $mail{$email} is only one item, but you might
have several items in the hash %mail if the DB file were still
open. Why not use the keys function to get a list of keys in
the hash?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>