以前我总是给出具体的例子,但这次给你们出一道足以使你们头发变白,身心疲惫的难题: #!/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... "; }
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... "; }