ziffgone
asked on
Scalar matching and if/elsif statement problems...
Here's my script. I want the script to be able to take the "email" input value and check and see if it already exists in a file, if not, add it, if it does, alert the user that it already exists.
Code:
-------------------------- ---------- ---------> >
#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Fcntl qw(:flock :seek);
print "Content-type: text/html\n\n";
sub add {
open(USER, ">>users.txt") or &dienice("Sorry\, there has been a problem\nadding you to our User File\.\nClick Back on Your Browser and try again\.: $!");
flock(USER, LOCK_EX);
seek(USER,0,2);
print USER param('email');
print USER "\n";
close(USER);
print <<EndHTML;
<html>
<head>
<script>
function goBack(){
history.go(-1);
}
</script>
</head>
<body onload="goBack();">
</body>
</html>
EndHTML
}
open(USER, "users.txt") or &dienice("Sorry\, there has been a problem\nadding you to our User File\.\nClick Back on Your Browser and try again\.: $!");
flock(USER, LOCK_SH);
seek(USER,0,0);
@list = <USER>;
close(USER);
$email = param('email');
$email =~ s/%(..)/pack("c",hex($1))/ ge;
$num = $#list;
for ($i = 0, $i => $num, $i++){
$comp = $list[$i];
if ($comp == $email){
print "Sorry, there has been an error, the e-mail address you entered already exists. Please Click Back on Your Browser and try again.<br>";
last;
}
elsif ($i => $num){
add();
last;
}
}
-------------------------- ---------- ---------< <
Can anyone tell me why the following statement always comes up true, despite the user's e-mail not being in the file?
-------------------------- ---------- ---------> >
if ($comp == $email){
print "Sorry, there has been an error, the e-mail address you entered already exists. Please Click Back on Your Browser and try again.<br>";
last;
}
-------------------------- ---------- ---------< <
And if I change it to the "eq" string comparison it always returns false, even when the e-mail address is in the file.
It was also suggested to me to use "List::Compare" with the "get_union" function, only to find that my Hosting company doesn't have the "List::Compare.pm" module installed.
Any ideas?
Code:
--------------------------
#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Fcntl qw(:flock :seek);
print "Content-type: text/html\n\n";
sub add {
open(USER, ">>users.txt") or &dienice("Sorry\, there has been a problem\nadding you to our User File\.\nClick Back on Your Browser and try again\.: $!");
flock(USER, LOCK_EX);
seek(USER,0,2);
print USER param('email');
print USER "\n";
close(USER);
print <<EndHTML;
<html>
<head>
<script>
function goBack(){
history.go(-1);
}
</script>
</head>
<body onload="goBack();">
</body>
</html>
EndHTML
}
open(USER, "users.txt") or &dienice("Sorry\, there has been a problem\nadding you to our User File\.\nClick Back on Your Browser and try again\.: $!");
flock(USER, LOCK_SH);
seek(USER,0,0);
@list = <USER>;
close(USER);
$email = param('email');
$email =~ s/%(..)/pack("c",hex($1))/
$num = $#list;
for ($i = 0, $i => $num, $i++){
$comp = $list[$i];
if ($comp == $email){
print "Sorry, there has been an error, the e-mail address you entered already exists. Please Click Back on Your Browser and try again.<br>";
last;
}
elsif ($i => $num){
add();
last;
}
}
--------------------------
Can anyone tell me why the following statement always comes up true, despite the user's e-mail not being in the file?
--------------------------
if ($comp == $email){
print "Sorry, there has been an error, the e-mail address you entered already exists. Please Click Back on Your Browser and try again.<br>";
last;
}
--------------------------
And if I change it to the "eq" string comparison it always returns false, even when the e-mail address is in the file.
It was also suggested to me to use "List::Compare" with the "get_union" function, only to find that my Hosting company doesn't have the "List::Compare.pm" module installed.
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Never mind, tested it myself.
BING, BING, BING, BING....
kandura gets the points!
I wanted to use the "while" function anyway, so your solution is a perfect fit.
Thanks a b'zillion kandura!
Regards...
BING, BING, BING, BING....
kandura gets the points!
I wanted to use the "while" function anyway, so your solution is a perfect fit.
Thanks a b'zillion kandura!
Regards...
ASKER