CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: String Operator Problem: Edit Log


May 7, 2017, 10:47 PM

Views: 1900
String Operator Problem

Hi, I know that this is really a basic program and I am still learning to it. I am learning Perl for almost three months now. I have a problem with my program. Can somebody tell me if what's wrong with my code? I tried to run the program but there's something wrong with the output.

It's supposed to be...
Input a string: Hello
Jinx again!

But instead the output would be (the sample that was shown above.) it ended in...
Input a string: Hello
Nice try!

The instruction is: Write a Perl program that has an array with values "Hello", "Hey", "Bye", "Yo" and ask the user for an input. If the input matches one of the elements in the array, print "Jinx again!", else print "Nice try."

Here's my code:

use strict;
use warnings;

my @words = ("Hello", "Hey", "Bye", "Yo");

my $my_words = @words;

print "Input a string: ";
my $string = <STDIN>;

if ($string eq $my_words) {
print "Jinx again!\n";
else {
print "Nice try!\n";

(This post was edited by iammgg on May 8, 2017, 3:42 AM)

Edit Log:
Post edited by iammgg (Novice) on May 7, 2017, 10:48 PM
Post edited by iammgg (Novice) on May 8, 2017, 3:42 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives