in reply to Basic Times Table excercise
Update: Perl6 added to end of subject.
Welcome to the monastery, jibberjabber! Since you are just starting down your Perl journey, you might want to consider taking the new Perl 6 path. (See all the buzz of Perl 5's sister language, recently released Perl 6, at http://perl6.org). For comparison with Perl 5, I have translated your code (and contributions by jcb and choroba) into Perl 6:
#!/usr/bin/env perl6 say q:heredoc/END/; Type in the correct answer, Hit enter key to continue, if it is not correct the program will not move on to a new problem, think about your answer, and try again, when it is the correct answer, it will tell you, and give a new problem. END while 1 { my $random = 11.rand.Int; my $random2 = 11.rand.Int; say "$random x $random2"; my $x = $random * $random2; while 1 { my $answer = get; if ($answer eq $x) { say "Great, $answer is correct."; say "Hit enter to continue, Ctrl+C to exit."; get; last; } else { say "Sorry, $x is not correct, please try again."; } } }
Note that in Perl 6, the strict and warnings pragmas are the default so do not have to be explicitly used.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Basic Times Table excercise
by 1nickt (Canon) on Feb 18, 2016 at 14:21 UTC | |
by Your Mother (Archbishop) on Feb 18, 2016 at 16:18 UTC | |
by LanX (Saint) on Feb 18, 2016 at 17:06 UTC | |
by Anonymous Monk on Feb 19, 2016 at 00:41 UTC | |
by LanX (Saint) on Feb 19, 2016 at 00:44 UTC | |
| |
by LanX (Saint) on Feb 18, 2016 at 17:22 UTC | |
by 1nickt (Canon) on Feb 18, 2016 at 18:30 UTC | |
by oiskuu (Hermit) on Feb 18, 2016 at 15:21 UTC | |
by jibberjabber (Novice) on Feb 18, 2016 at 16:39 UTC | |
by Your Mother (Archbishop) on Feb 18, 2016 at 16:52 UTC | |
by jibberjabber (Novice) on Feb 19, 2016 at 15:04 UTC | |
by Anonymous Monk on Feb 18, 2016 at 15:11 UTC |