RE: Getting my head round hashes
One nice way to learn about hashes, arrays, scalars and references, is to learn the perl debugger and just experiment. There is a perl debugger tutorial in the perl documentation. You can print out the arrays and hashes w/o putting print statements into your code, and that makes the experimentation very easy and interesting. Mark -Original Message- From: Greenhalgh David [mailto:[EMAIL PROTECTED] Sent: Thursday, June 05, 2003 1:16 PM To: [EMAIL PROTECTED] Subject: Getting my head round hashes Hi all, I have a script which mostly works, but when I get to the part with hashes, it stops. I'm obviously doing something very basically wrong, but I can't see what. (been staring at so long it could be anything.) A segment of the code is below: #!/usr/local/perl -wT use strict; use CGI; # Do some stuff to identify the value of $marker which will be a number # Do MySQL query to grab the data to be manipulated my $dbh=connect(DBI:mysql:database, user, password); my $query=(SELECT task_ID, priority FROM task_list WHERE priority $marker); my $reponse-prepare($query); $response-execute; # $ response should now contain a # reference to a hash filled with task_ID, priority pairs # Dereference $response my %hash=%($response); $response-finish; # Subtract 1 from each value in the hash my ($key, $priority, %newhash); foreach $key (keys(%hash)){ my $priority=$hash{$key}--; %newhash=($key, $priority); } # Put the new $priority values into the MySQL table $query=(UPDATE task_list SET priority=? WHERE task_ID=?); $response-prepare($query); foreach $key (keys{%newhash}){ $priority=$newhash{$key}; $response-execute($priority, $key); } $response-finish; # Test the result print Content-Type: text/html\n\n; $query=(SELECT task_ID, priority FROM task_list); $response-prepare($query); $response-execute; while($key, $priority){ print Priority: $priority Task Ident: $keybr\n\n; } Would someone be patient enough to point out the mistake? Thanks Dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Problems getting a simple form to work.
Undefined subroutine main::param called at simpleform.cgi line 6. Is the error I get for your script when I execute it from http://www.mikyo.com/cgi-bin/simpleform.cgi If you want to try what I did, do the following: 1. type in http://www.mikyo.com/cgi-bin/simpleform.cgi to your web browser 2. You will get the error above. Are you sure the CGI module is installed on Hypermart's servers? You can send them an email to see. CGI module is not a standard part of my web hoster either, so you might want to find a hosting site that will install it for you. There are ways you can install CPAN modules yourself on the Hypermart server, but I think you need to rebuild the module with some details about where you'll be installing it. This is covered in 12.7 and 12.17 in Perl Cookbook. Mark I tried to go to Hypermart to look at their CGI implementation, that is, where they say to get access to your CGI programs, but I couldn't until I signed up. They have a free option, but oddly they require a credit card even for the zero-dollar option. So, I would look at their CGI FAQ ( -Original Message- From: Mike Butler [mailto:[EMAIL PROTECTED] Sent: Friday, April 04, 2003 12:58 PM To: Li Ngok Lam; [EMAIL PROTECTED] Subject: RE: Problems getting a simple form to work. Hi Li, Rob and Mark. Thanks for your help. My site is being hosted by Hypermart, so I don't have access to /var/log/httpd. My new simpleform.cgi now looks like this: #!/usr/local/bin/perl -wT use CGI; use strict; $username = param('username'); print Content-type: text/plain\n\n; print You entered: $username\n; The permissions look like this: Permissions for cgi-bin: rwxr-xr-x Permissions for simpleform.cgi rwxr-xr-x Permissions for simpleform.htm: rwxr-xr-x I have changed form method=post action=../cgi-bin/simpleform.pl to form method=post action=http://www.mikyo.com/cgi- bin/simpleform.cgi. I am still getting the 500 error. Thanks, - Mike -Original Message- From: Li Ngok Lam [mailto:[EMAIL PROTECTED] Sent: Friday, April 04, 2003 1:16 PM To: Mike Butler; [EMAIL PROTECTED] Subject: Re: Problems getting a simple form to work. [..] Can anyone tell me what I'm doing wrong? Also, is there a way to turn on error.log? Actually, error.log is always turned on... If you are not running the server on yours own, ask the server admin where is the error.log located. [..] Permissions for cgi-bin: rwxr-xr-x Permissions for simpleform.htm: rwxr-xr-x What about your script ? simpleform.pl [..] #!/usr/local/bin/perl use CGI; # You missed this $username = param('username'); You can't ask a value from param without use CGI in this case. print Content-type: text/plain\n\n; print You entered: $username\n; One more point, when you are going to write a script for real running, always use strict You will know how pain it is to remember all the var names that you've declared along the whole script. And most likely have to rewrite the whole thing again when touching to maintenence or debugging... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]