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:
Extremely Noobish Problem: IF


New User

Sep 18, 2012, 12:33 PM

Post #1 of 3 (1173 views)
Extremely Noobish Problem: IF Can't Post

Hi everyone.
I've actually started learning perl yesterday, haven't made much progress, but I read more than I write.

However, I have a very simple question.
I've searched google for operators for non-numerical values, such as "Yes".

This is my script:

say "Please enter first number"; 
my $number1 = <STDIN>;
chomp $number1;
say "Please enter second number";
my $number2 = <STDIN>;
chomp $number2;
my $add = $number1 + $number2;
say "Are you sure you want to add these two numbers together?";
my $yes = <STDIN>;
if ($yes == 1) {
print "The answer is $add \n";

else {
print "Okay then, I'll keep it to myself.";

If I replace

if ($yes == 1)


if ($yes == "Yes")

it says the argument isn't numeric in value. If I use only "=" it says it found a conditional that should be "==". Both changes in the script end up displaying the result whatever the answer is.

tl;dr, Instead of 1 and 0, how do I make it more user-friendly per se with Yes and No.

My guess is I need to predefine $yes, but how can I do so when $yes is defined by <STDIN> ?

(This post was edited by kolyonl on Sep 18, 2012, 12:34 PM)

Veteran / Moderator

Sep 18, 2012, 12:52 PM

Post #2 of 3 (1170 views)
Re: [kolyonl] Extremely Noobish Problem: IF [In reply to] Can't Post

You're looking for the 'eq' operator.

if ($yes eq 'Yes')

New User

Sep 18, 2012, 12:54 PM

Post #3 of 3 (1168 views)
Re: [FishMonger] Extremely Noobish Problem: IF [In reply to] Can't Post

Thank you. Problem solved. Smile On to the next one.


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

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