作者yingwan (yingwan)
看板Perl
标题[问题] exists的用法
时间Mon Oct 20 03:26:53 2008
又卡住了....只要上来求助前辈了
我想要用perl CGI 写一个使用户登入的网页
程式会先检查档案里里有没有这个帐号存在,
有的话就会出现该用户的email,没有的话程式就会说"该用户不存在"
写了半天网页都一直出现email,也不管有没有哪个ID存在
希望前辈们帮我看看我是哪里写错,谢谢大家
#!/usr/bin/perl
#--------------------------------------------------------
#Login page for userID and password
#if userID already exist or missing input, show error msg
#otherwise, show user's email address
#--------------------------------------------------------
use CGI qw(:standard -debug);
use CGI::Carp qw(fatalsToBrowser);
#get input
$userid= param ("userid");
$password= param ("password");
$file="hw6-22.out";
open(IN,$file) || die "can't read $file";
@all = <IN> ;
close(IN);
chomp @all;
#checking for existing userID
%all=();
foreach (@all) {
($userid, $password, $email) = split(/,/,$_);
$all{$userid} =$password;
}
if (exists $all{$userid}) {
print header();
print start_html(-title=>"Existing ID");
print h2("Your email address:");
print p("$email");
exit;
}
# check for missing input
if ($userid eq "") { push(@missing,"User ID"); }
if ($password eq "") {push (@missing, "Password");}
$missing= join(", ",@missing);
if ($missing) {
print header();
print start_html(-title=>"missing input");
print h2("Incomplete Input");
print p("You did not enter <b>$missing</b>");
print end_html();
exit;
}
else
{
print header();
print start_html(-title=>"Not exist");
print p("<b>The UserId does not exist </b>");
print end_html();
exit;
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 149.159.132.73