RE: referencing a flat file DB
Hi Jon Hey, is this a competition to identify lapdancers or something? If so, don't forget to post the URL up here when you've got it working ;-) (especially since we now know all the answers) Anyway, one thing that might be causing problems is these two lines in your one_time sub $compare = { split (/:/, $stats)}; @records = \$compare; I think you'd be better off to use: @records = split (/:/, $stats) At the moment you are splitting to a scalar (which I think just puts the first (or is it the last?) value from that split into the scalar) and then assigning a reference to that scalar as an array. I'm sure that's not good for you (and I'm a bit surprised that -w didn't pick it up, or haven't you tried it from the command line?) Other than that I can't see anything that should actually stop it working. It's not the prettiest code I've ever seen though... Cheers Mark C Hello everyone, I am trying to create a simple cgi script that if a user enters the correct information on a contest form, they are entered into a flat-file DB. This I have conquered. My next feat is that before I write their personal information into the DB, I am comparing 3 fields from the DB to 3 fields being submitted by the user for duplicate submissions in sub one_time (the fields are phone number fields). The problem is, is that I never get a match and the user is able to submit an infinite amount of time. Here is my source code. It's only about 65 lines. Thank you for your help!
Re: referencing a flat file DB
On Thu, Jun 28, 2001 at 09:06:38AM -0700, Jon Riddle wrote: Be forewarned, what follows is a critique of code you didn't ask about. #!/usr/local/bin/perl -w use CGI; use CGI::Carp qw(carpout fatalsToBrowser); Always: use strict; when debugging code. $Q = CGI; This assigns the string 'CGI' to $Q. I doubt that's what you intended. my $Q = new CGI; Remove this from here: $content_length = $ENV{'CONTENT_LENGTH'}; read (STDIN, $posted_information, $content_length); $posted_information =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack (C, hex ($1))/eg; $posted_information =~ s/\+/ /g; @fields = split (//, $posted_information); to here. Do not roll your own CGI parser, you will almost assuredly miss something. ($label, $name) = split (/=/, $fields[0]); ($label, $street) = split (/=/, $fields[1]); ($label, $city) = split (/=/, $fields[2]); ($label, $state) = split (/=/, $fields[3]); ($label, $zip) = split (/=/, $fields[4]); ($label, $PHONE_AREA) = split (/=/, $fields[5]); ($label, $PHONE_PRE) = split (/=/, $fields[6]); ($label, $PHONE_SUFF) = split (/=/, $fields[7]); ($label, $serviceProvider) = split (/=/, $fields[8]); ($label, $lapDance) = split (/=/, $fields[9]); ($label, $lapDance2) = split (/=/, $fields[10]); ($label, $lapDance3) = split (/=/, $fields[11]); ($label, $lapDance4) = split (/=/, $fields[12]); ($label, $lapDance5) = split (/=/, $fields[13]); Use: my $name = $Q-param('name' ); my $street = $Q-param('street'); etc. Better yet, don't assign them to temporary variables, use them directly when necessary, or stick them in a hash. #Compares correct anwsers $lapResults .= ,$lapDance,$lapDance2,$lapDance3,$lapDance4,$lapDance5; if ($lapResults eq ,AvaVincent,JessicaDrake,JewellDeNyle,ShaylaLaVeaux,ShaySweet) { $correct = 1} This looks like a bad way of doing this. You should probably put the expected names in an array, then iterate over each of your parameters and make sure they're in the array. my @params = ($lapDance, $lapDance2, $lapDance3, $lapDance4, $lapDance5); my $correct = 1; for (my $i = 0; $i @params; $i++) { if ($params[$i] ne $EXPECTED_NAMES[$i]) { $correct = 0; last; } } if (!$correct) { print $Q-redirect('http://www.ten.com/contest/thanklost.htm'); } else { if (one_time(1)) { print $Q-redirect('http://www.ten.com/contest/already.html'); } else { open (OUTPUT, lapdance.db) || die Cannot open lapdance.db: $!; print OUTPUT $name, :, $street, :, $city, :, $state, :, $zip,:, $PHONE_AREA, :, $PHONE_PRE, :, $PHONE_SUFF,\n; Use join: print OUTPUT join(:, $name, $street, $city, $state, ...), \n; close OUTPUT; print $Q-redirect('http://www.ten.com/contest/thankwon.htm'); } } # Routine that checks DB for previous valid # entry comparing telephone number sub one_time { open (VARIFY, lapdance.db) || die Cannot open lapdance.db: $!; while (VARIFY) { $stats = VARIFY; This: $compare = { split (/:/, $stats)}; @records = \$compare; is very likely the source of your asked problem. You are constructing an anonymous hash with '$compare = { split (/:/, $stats)}', then assigning a reference to that anonymous hash to $records[0]. Replace this with: @records = split(/:/, $stats); if (($records[6] eq $PHONE_AREA) ($records[7] eq $PHONE_PRE) ($records[8] eq $PHONE_SUFF)) { $sorry = 1; } } close VARIFY; return $sorry; } # EOF ### Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
Re: referencing a flat file DB
On Thu, Jun 28, 2001 at 05:34:22PM +0100, mark crowe (JIC) wrote: $compare = { split (/:/, $stats)}; @records = \$compare; I think you'd be better off to use: @records = split (/:/, $stats) While this is correct.. At the moment you are splitting to a scalar (which I think just puts the first (or is it the last?) value from that split into the scalar) and then assigning a reference to that scalar as an array. this isn't. He's creating an anonymous hash with { split(/:/, $stats) }, then assigning it to $compare. He then assigns a reference to $compare to $records[0], which makes it a reference to a hash reference. I'm sure that's not good for you (and I'm a bit surprised that -w didn't pick it up, or haven't you tried it from the command line?) The code will only cause a warning if the split returns an odd number of elements. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
RE: referencing a flat file DB
Hello all, I would like to take a moment to thank everyone who helped me out on my project. I am obviously new to Perl and am a total hack, but eventually, I will become proficient. For those that are wondering, my lap dance program is just a small contest for members of www.ten.com and yes, I do work in the Porn industry (Interactive Gallery, subsidiary of Nasdaq:NOOF). Perl is alive and well in the adult world and is even traded on Wall street, the stock that is! We have an engineering team that are all mongers, however they have bigger fish to fry then my little contest program. So, thanks again for the help and very constructive criticisms. One day, I will be the mentor! P.S., I would give out a user name and password, but the likeliness of their being underage participants in this forum is too great. Jon Riddle Interactive Gallery Inc. Phone- 818-501-4486 ext. 3037 Email- [EMAIL PROTECTED] The three great virtues of a programmer are laziness, impatience and hubris. Larry Wall