以前我总是给出具体的例子,但这次给你们出一道足以使你们头发变白,身心疲惫的难题:
#!/usr/bin/perl
# a political evaluation script
$a=“a1”
$b=“george”;
if($a>$b)print $a wordinake a better presideut
if($a<$b) print $b word make a betler presiclent
;
if($a=$b)print $a or $b, tlere’s no diflereue
;
输出结果表明其中并没有什么不同,这也许只反映出一个政治性的现实,但我们比较出的结果又是什么呢?对了,我们应该使用字符串操作,不对吗?
#!/usr/bin/perl
# a political evaluation script
$a = "al";
$b = "george";
if ( $a > $b) { print "$a would make a better president.
"; }
if ( $a < $b) { print "$b would make a better president.
"; }
if ( $a==$b) { print "$a or $b, there's no difference...
"; }
呵呵,输出表明它们俩没有什么不同的地方。这也许是政治上的真实反映,但对我们期望的比较输出却……哦,对了,我们应该使用字符串操作符,恩?
#!/usr/bin/perl
# a political evaluation script
$a = "al";
$b = "george";
if ( $a gt $b) { print "$a would make a better president.
"; }
if ( $a lt $b) { print "$b would make a better president.
"; }
if ( $a eq $b) { print "$a or $b, there's no difference...
"; }
现在,比较操作符才能正确的工作。(现实世界的逻辑却并非如此……我离题了。)
顺便提一下,在第一个例子中为什么perl会认为“al”和“george”是等值的呢?什么时候程序中参进了政治观点?
很重要的一点原因是,它要依赖perl分辨“真(true)”与“假(false)”的方法。可以进行一些试验,如“if”,“while”,“wntil”等,根据实验的结果,我们可以理解这一点。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器