
kolyonl
New User
Sep 18, 2012, 12:33 PM
Post #1 of 3
(1544 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 with 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)
|