Possible Duplicate:
How do I compare two strings in Perl?
Why does this script always return “You won”?
print "Choose heads or tails :\n";
$answer = <STDIN>;
chomp $answer;
if( $answer == "heads" ) {
print "You won\n";
}
else {
print "Moron! You lost.\n"
}
And what should be the correct code for the same?
String comparation in Perl uses
eqinstead of==. Try:If you are comparing numbers you use
==.Read more about it in a post at perlmonks.
When learning Perl I suggest you start your scripts with
use strict;anduse warnings;. That way you will get a warning for this kind of operation. And it will also help you with misspelled variables.