perl compare function

W

worlman385

for the code below i got error at line 14
if ( $string1 gt $string2 )
print "$string1 $string2";

what's the problem?

thanks


print "Enter the first string: ";
$string1 = <STDIN>;
print "Enter the second string: ";
$string2 = <STDIN>;

chomp $string1;
chomp $string2;

if ( $string1 gt $string2 )
print "$string1 $string2";
elsif ( $string1 lt $string2 )
print "$string2 $string1";
elsif ( $string1 eq $string2 )
print "$string1\n$string2";

exit;
 
F

FeelLikeANut

for the code below i got error at line 14
if ( $string1 gt $string2 )
print "$string1 $string2";

what's the problem?

thanks

print "Enter the first string: ";
$string1 = <STDIN>;
print "Enter the second string: ";
$string2 = <STDIN>;

chomp $string1;
chomp $string2;

if ( $string1 gt $string2 )
print "$string1 $string2";
elsif ( $string1 lt $string2 )
print "$string2 $string1";
elsif ( $string1 eq $string2 )
print "$string1\n$string2";

exit;

Perl requires curly braces around even one-lined if statements.

if ( $string1 gt $string2 ) {
print "$string1 $string2";
}
 
J

John Bokma

for the code below i got error at line 14
if ( $string1 gt $string2 )
print "$string1 $string2";

what's the problem?

You not posting the exact error message...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top