in reply to Basic Times Table excercise

Hi jibberjabber, welcome to the Monastery!

Once the while loop is left, you know the answer was correct (as that's the condition to exit the loop). You need to check for the wrong answer inside the loop:

while (1) { chomp( my $answer = <STDIN> ); if ($answer eq $x) { print "Great, $answer is correct.\n"; print "Hit enter to continue, Ctrl+C to exit."; <STDIN>; last } else { print "Sorry, $x is not correct, please try again.\n"; } }

Why do you use the string comparison eq instead of the numeric == ?

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Basic Times Table excercise
by jibberjabber (Novice) on Feb 17, 2016 at 01:59 UTC

    Thank you for the reply and the welcome,

    And the "tip", this makes sense to me now.

    Why did I use the string comparison eq instead of the numeric == ?

    Actually it is because when I wrote the script, I had not gotten that far into any tutorials. What I found was intended for text only. Then I looked at some on generating random numbers, but had not seen about the numeric comparisons yet. Just last night or yesterday I did see some on that, but still have not tried using the IE: == or != and I just had not yet tried doing with them. In a nutshell, I was not yet aware of the numeric options. Your reply gives me a "new approach" to this, and as soon as I get the chance I am going to experiment some more and see how it goes. Thanks a whole bunch on this and for taking the time. Thanks