When I started the topic, I had not intended it to be just for trying to get help on my first Perl script, but also a topic where others can share theirs as well and ask any questions
they may have. So any way, it dawned on me the title needed to be changed from
"My" to yours or "our", ??
So any way, with that said. Below is my first script.
--------- end edited-------------------
I have been aware of Perl for several years, and seen it used a lot , especially in
Debian and other Linux systems, as well as unix. So any way, I looked at some tutorials
today, and got started on this:
Code: Select all
#!/usr/bin/perl
#use strict;
#use warnings;
print "Times tables 1 through 10\n";
print " 3 x 5 = type answer: ";
$answer = <STDIN>;
chomp $answer;
while ( $answer ne "15" ) {
print "$answer is not correct try again: ";
$answer = <STDIN>;
chomp $answer;
}
print "Great $answer is correct.\n";
print "Hit enter key to continue: ";
$_ = <STDIN>;
if ( $answer eq "15" ) {
print "15 is correct\n";
}
#else {(this is not doing anything)
# print "Wrong !the correct answer is 15\n";
#}(besides that, maybe I do not want to give the correct answer
#that easy. Go on to next problem.
#note : I read that this may not work on some sytems to clear the
#screen but it does on mine.
print "\033[2J";
print " 5 x 5 = type answer: ";
$answer = <STDIN>;
chomp $answer;
while ( $answer ne "25" ) {
print "$answer is not correct try again: ";
$answer = <STDIN>;
chomp $answer;
}
print "Great $answer is correct.\n";
print "Hit enter key to continue: ";
$_ = <STDIN>;
if ( $answer eq "25" ) {
print "25 is correct\n";
}
# goes on to next problem-------------
print "\033[2J";
print " 2 x 3 = type answer: ";
#The <STDIN> is the way to read keyboard input
$answer = <STDIN>;
chomp $answer;
while ( $answer ne "6" ) {
print "$answer is not correct try again: ";
$answer = <STDIN>;
chomp $answer;
}
print "Great $answer is correct.\n";
print "Hit enter key to continue: ";
$_ = <STDIN>;
if ( $answer eq "6" ) {
print "6 (six) is correct\n";
}
#On to next problem, I have decided to include the number in text
#as well, to help her learn the numbers in english.
but it is more fun to try to make my own.
I did do one using Qbasic, on Dos years ago that is pretty neat, I still have it and can run it on dosbox, however I would like to try to do this with Perl. I like perl so far, I think I can learn to work with it.
Similar, with the first qbasic script, it was over 100 lines of code, but when I shared it,
some body else showed me a way to do it with just a few lines code, that generated the numbers 1 through 10, in pairs randomly, then if the correct answer was entered
it genarated a new pair IE: 2 x 4=, .
I can make this work, like it is, with just a new problem, one after another, using the same code, but it would be well over 500 lines of code, just to cover the multiplication tables, 1 through 10. And it would not be random. So anyway, any ideas or examples would be welcome, how ever there are lots of tutorials I can keep reading as well, and maybe I will get some better idea.
Any way, just wanted to share this, trying it with bash I never even got this far, I like Perl.