I'm creating a little program that chooses between 3 different languages and outputs either, Ruby, Python, or a random element from an array.
However my if statement apparently has a syntax error in it because no matter what I try, I keep getting this:
syntax error at test.pl line 15, near ") {"
syntax error at test.pl line 17, near "} elsif"
Execution of test.pl aborted due to compilation errors.
Here's the code I have as of right now:
sub welcome {
my @choices = qw( Perl Python Ruby );
my $lang = 3;
print("Welcome, to the test script, this will test what language you would like to learn.. In order to find out these choices, write this same definition in all three different languages\n");
print("There are", $lang, "languages to chose from please pick one:\n");
print "@choices";
my $choice = <STDIN>;
chomp $choice
if ($choice = "Ruby") {
print("You have chosen Ruby!\n");
} elsif ($choice = "Python") {
print("You have chosen Python!\n");
} else {
print("You're already writing in Perl!! Let me choose for you:");
my $rand_elm = @choices[rand @choices];
}
}
welcome();
I've also tried this:
my $choice = <STDIN>;
chomp $choice
if ($choice = "Ruby")
{
print("You have chosen Ruby!\n");
}
elsif ($choice = "Python")
{
print("You have chosen Python!\n");
}
else
{
print("You're already writing in Perl!! Let me choose for you:");
my $rand_elm = @choices[rand @choices];
}
}
I also tried using strict;
and warnings
I have also tried with STDIN
All of these output the same error. What is causing this error?