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

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top