Perl:strings.pl第8行的语法错误,接近"){"

时间:2015-01-22 22:41:35

标签: perl

这是我的代码:

use strict; use warnings;

my $s1 = "Hello";
my $s2 = "World\n";
my $s3 = $s1 . " " . $s2;
print $s3

if      ($s1 eq $s2) {print "same string\n"}
elsif ($s1 gt $s2) {print "$s1 is greater than $s2\n"}
elsif ($s1 lt $s2) {print "$s1 is less than $s2\n"}

但每次我尝试运行此操作时,都会收到此错误,

  

strings.pl第8行的语法错误,靠近“){”

我不明白为什么我会得到它。

1 个答案:

答案 0 :(得分:3)

添加“;”在“print $ s3”之后

use strict; use warnings;

my $s1 = "Hello";
my $s2 = "World\n";
my $s3 = $s1 . " " . $s2;
print $s3; 

if      ($s1 eq $s2) {print "same string\n"}
elsif ($s1 gt $s2) {print "$s1 is greater than $s2\n"}
elsif ($s1 lt $s2) {print "$s1 is less than $s2\n"}