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 (Abbot) on Feb 18, 2016 at 14:21 UTC

    jibberjabber, be warned that this poster is referring to an unfinished language that is NOT COMPATIBLE with Perl, and is not to be used in production, according to its own docs. "Perl6" is NOT the latest version of Perl.

    u65: are you seriously going to try to pollute every thread with a plug for your new hobby (well, I mean obviously only the ones with trivial questions that "Perl6" can solve) ?

    The way forward always starts with a minimal test.

      It's interesting to agree with both of you. I liked seeing the Perl6 code. I agree the thread was hijacked a bit and the caveats you gave would have been better in u65's node. Interesting times.

        > I liked seeing the Perl6 code. I agree the thread was hijacked a bit

        Yep, me too!

        This could have been easily avoided by marking the replies title with a trailing (Perl6) or a leading [Perl6] much like we use [OT] marks elsewhere.

        update

        added consideration and author /msg'ed

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

      1nickt, when exactly did I miss that you've been promoted to a moderator of the monastery who's in charge to censor contributions?

      Instead of using words like "pollute" and stirring an inquisition/witch hunt climate what about demonstrating your contributions to Perl5 and showing alternatives to development in a positive way?

      It's my personal believe that Perl6 should have been better named Perl++ from the beginning and that this resulted in a marketing disaster.

      But I'd really prefer to see positive contributions to Perl5 by the critics, instead of spilling hatred against the P6 folks.

      Nota Bene: it took Perl5 over 15 years to add function signatures to core and it's still experimental.

      Now how is this a convincing position to damage other contributions?

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      ) well, easy to say in hindsight... but I'm repeating this since 2008 ( update and since it's Larry's decision I have to accept it. It's his language!)

        Hi LanX,

        I am certainly no moderator, just a monk with an opinion. I believe you might be confused about what censorship is. You seem to want me to self-censor my comments about how I feel that it's inappropriate and counter-productive to the monastery's mission to post here about "Perl6", and 1,000 times more so when it is in the form of blatant thread-hijacking, and now even new-user poaching.

        This OP came stating that he is a Perl beginner and he asked a question. u65 jumped in offering code in a different language than he asked about, wrapped up in "See all the buzz" hype. He explicitly said that the OP should consider a different path than the one he had begun by asking a question here. These are facts, not a conspiracy theory.

        I have no "hatred" of any person, I just hate freeloading, and I do tend to speak up about it on- and off-line. I also try to contribute where I can, as you can easily see by reading the nodes I've posted. I am a monk here and I contribute here because I wish to further my knowledge of Perl programming by teaching what I know and learning what I don't know from others. I'm pretty sure that's the mission of the monastery, and "Perl6", while it may be interesting in any number of ways, is most charitably described as a distraction from that mission, and most accurately, as an opportunistic land-grabber trying to subvert and co-opt it.

        Now here's a question: have you noticed that the monks who are most defensive about "Perl6" are mostly the same handful of most senior ones? In other words, the ones who are most accomplished in Perl 5 and thus have least need of the learning that the monastery exists to foster? Perhaps some of those most expert monks should put themselves in the position of a brand new monk, or an average programmer who doesn't learn new languages for recreation but is just trying to improve his skills to stay employed, or really any one of the thousands of non-expert users of this site, and think about why those folks come here and what they are seeking.


        The way forward always starts with a minimal test.

      If there is a fault in what u65 posted, it may be in the lack of idiomatic form. I say meh, there.

      Personally, I welcome such contributions that concisely and conclusively demonstrate the merits of perl6 feature set, where it actually matters. In this regard, I want people with real perl6 expertise to be able to freely contribute, without the fear of backlash. You are not helping.

      Thanks "1nickt",for letting me know on this,it is important to know that and if it is not comaptible, I don't think I would want to install it. This would be a different topic,but using a Debian system,it is very important to only use programs that come from the Debian repos,and are compatible with the system. "perl" is. So in other words, the code would not work in perl ? I have not tried it yet. I like the part where the instructions are done like this:

      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
      I did just now try it from the command line,
      perl 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
      But it does not seem to work with "perl"

      I guess that is why, perhaps once I get a better understanding of the basic perl commands ,etc I will be able to do more with that.

      Thank you as well, U65 for sharing that about perl6 , I don't see anything wrong with sharing it, but it would have been nice to mention it does not work with perl,but anyway thank you

      Well any way than you every body on this, I guess for now that is about it

        Perl5/Perl6 are different but won't interfere on the same box any more than Ruby and Python would. Perl5 has HEREDOCs too; syntax is a bit different.

        print <<""; Some things on more than one line with a TRAILING NEWLINE # ^^^ blank line matches "" in print and ends statement print <<"orWITHyourOwnSTYLEendTag"; Some things on... orWITHyourOwnSTYLEendTag

        A lot of devs find the "" blank line ending HEREDOC a bit offensive/dangerous but I like it. :P More: Here documents, or how to create multi-line strings in Perl.

      u65 is providing information that may actually be useful; you're the one polluting the thread with your hatred of Perl 6.