微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

perl编写CGI 尝试

一直觉得perl写网页是一件很原始的事情,编写CGI-使用perl的书刚借来就弄丢了。后来帮群里的小朋友讨论到CGI,觉得有点意思,就尝试学了一下,编写了一个简单的,保存邮件列表,和现实邮件列表的就简单CGI,如下:
#!/opt/lampp/bin/perl
use CGI;
use Data::Dumper;
use Storable;
my @values=('CharityBase','Linux kernel mailing list','MailChimp','Melissa Data');
our  $q        = CGI->new();
my $name =$q->param("name");
my $mail=$q->param("mail");
my $list=$q->param("organnisation");
print $q->header;
print  $q->start_html({-title=>"Join a Mainlist"}  );
if($q->param("all")  )
{
#display name list
	my $allhash1 = retrieve('datafile');
    print $q->h1( {-align => 'CENTER' },'This all mail list!');
	foreach $tmp1 (@values)
	{
            print $q->h3("$tmp1");
       		my $firstlist= $allhash1->{$tmp1};
        	foreach (@$firstlist){
           	printf $q->ul( $q->li("%s (%s)") ),$_->{name},$_->{mail};
        	}
	}
} else {
	if ($q->param('submit') ){
	    
        if(-s 'datafile' == 0){
	        my $tmphash={};
	        foreach my $key (@values)
	        {
	        $tmphash->{$key}=[];
	        }
	        store $tmphash,'datafile';
	    }
        my $allhash = retrieve('datafile');
	    my $element = {
           name =>$name,mail =>$mail,};
        push @{$allhash->{$list}},$element;
	    store $allhash,'datafile';
	}
    
    print $q->h1( { -align => 'CENTER' },"Sign Up Free!" );
	print $q->start_multipart_form({-action=>"test.cgi",-method=>"POST"});
	print $q->p('Please Enter your name',$q->textfield({-name=>"name",-value=>''}),);
	print $q->p('Please Enter your mail',$q->textfield({-name=>"mail",);
	print $q->p('Please choose:',$q->popup_menu({-name=>'organnisation',-values=>\@values,}),);
	print $q->p(  $q->submit({-name=>"submit",-value=>'submit'}),$q->reset({-name=>"reset",-value=>'clear'}),$q->submit({-name=>"all",-value=>'show all list '}),);
	print $q->end_form();
}


	 print $q->end_html;


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐