用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - perl代码库

perl 用HTML格式列表和表的快捷方式

2012-10-15 作者: 神马举报

[perl]代码库

#-----------------------------
print ol ( li ( [ qw ( red blue green ) ] ) );
# <OL><LI>red</LI> <LI>blue</LI> <LI>green</LI></OL>

@names = qw ( Larry Moe Curly );
print ul ( li ( { -TYPE => "disc" }, \@names ) );
# <UL><LI TYPE="disc">Larry</LI> <LI TYPE="disc">Moe</LI>
#
#     <LI TYPE="disc">Curly</LI></UL>
#-----------------------------
print li ( "alpha" );
#     <LI>alpha</LI>

print li ( [ "alpha", "omega"] );
#     <LI>alpha</LI> <LI>omega</LI>
#-----------------------------
use CGI qw ( :standard :html3 );

%hash = (
            "Wisconsin"  => [ "Superior", "Lake Geneva", "Madison" ],
            "Colorado"   => [ "Denver", "Fort Collins", "Boulder" ],
            "Texas"      => [ "Plano", "Austin", "Fort Stockton" ],
            "California" => [ "Sebastopol", "Santa Rosa", "Berkeley" ],
        );

$\ = "\n";

print "<TABLE> <CAPTION>Cities I Have Known</CAPTION>";
print Tr ( th [qw ( State Cities ) ] );
for $k ( sort keys %hash )
{
	print Tr ( th ( $k ), td ( [ sort @ {$hash{$k}} ] ) );
}
print "</TABLE>";
#-----------------------------
# <TABLE> <CAPTION>Cities I Have Known</CAPTION>
#
#     <TR><TH>State</TH> <TH>Cities</TH></TR>
#
#     <TR><TH>California</TH> <TD>Berkeley</TD> <TD>Santa Rosa</TD>
#
# 	  <TD>Sebastopol</TD> </TR>
#
#     <TR><TH>Colorado</TH> <TD>Boulder</TD> <TD>Denver</TD>
#
# 	  <TD>Fort Collins</TD> </TR>
#
#     <TR><TH>Texas</TH> <TD>Austin</TD> <TD>Fort Stockton</TD>
#
# 	  <TD>Plano</TD></TR>
#
#     <TR><TH>Wisconsin</TH> <TD>Lake Geneva</TD> <TD>Madison</TD>
#
# 	  <TD>Superior</TD></TR>
#
# </TABLE>
#-----------------------------
print table
caption ( 'Cities I have Known' ),
Tr ( th [qw ( State Cities ) ] ),
map { Tr ( th ( $_ ), td ( [ sort @{$hash{$_}} ] ) ) } sort keys %hash;
#-----------------------------
# download the following standalone program
#!/usr/bin/perl
# salcheck - check for salaries
use DBI;
use CGI qw ( :standard :html3 );

$limit = param ( "LIMIT" );

print header(), start_html ( "Salary Query" ),
h1 ( "Search" ),
start_form(),
p ( "Enter minimum salary", textfield ( "LIMIT" ) ),
submit(),
end_form();

if ( defined $limit )
{
	$dbh = DBI->connect ( "dbi:mysql:somedb:server.host.dom:3306",
	                      "username", "password" )
	       or die "Connecting: $DBI::errstr";
	$sth = $dbh->prepare ( "SELECT name,salary FROM employees
	                       WHERE salary > $limit" )
	       or die "Preparing: ", $dbh->errstr;
	$sth->execute
	or die "Executing: ", $sth->errstr;

	print h1 ( "Results" ), "<TABLE BORDER=1>";

	while ( @row = $sth->fetchrow() )
	{
		print Tr ( td ( \@row ) );
	}

	print "</TABLE>\n";
	$sth->finish;
	$dbh->disconnect;
}

print end_html();

#-----------------------------


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...