[Purdue-pm] Perl 6

Mark Senn mark at purdue.edu
Tue Jul 28 05:48:22 PDT 2015

Perl 6 is a much better language than Perl 5 in my opinion.  I'm using
it for simple programs now and am very happy with it.  Perl 5 has
    Comprehensive Perl Archive Network (CPAN)
    153,637 open source Perl modules ready to download and use
and Perl 6 has
    Perl 6 Modules
    a few hundred Perl 6 modules (that aren't as mature
    or tested as Perl 5 modules)

Perl 5 and Perl 6 are both planned to be further developed and supported
in the future.  I like to use what I think are the best tools possible
so I plan to use Perl 6.  I suggest you use Perl 6 for small simple
programs that are not mission-critical now because trying to learn Perl
6 all at one time later may be prohibitively difficult.  Perl 6 is
experimental now, a production version will be released later---this
year has been mentioned---but the date has slipped before.

You can see the notes from my July 15, 2015 talk
    Let Perl 6 Do It
(Go into full screen mode and hit the down arrow key repeatedly
to see the talk unfold (that works for me using acroread).
Warning: this relies a lot on what I said during the talk.)

Here is a complete Perl 6 program for Linux that defines command line
options (-d, --digits, -p, --passlen, -r, --rows, -u, --uppercase),
their default values, and prints $rows rows of $cols columns of $passlen
character long random passwords.


  sub MAIN
      Bool :d(:$digits),
      Int  :p(:$passlen)   =  8,
      Int  :r(:$rows)      = 20,
      Bool :u(:$uppercase)
      my @char = 'a' .. 'z';
      ($digits)     and  @char.push('0' .. '9');
      ($uppercase)  and  @char.push('A' .. 'Z');
      my $cols = (78 / ($passlen + 1)).Int;
      for 1 .. $rows
          # (
          #     Originally I had
          #         say (@char.roll($passlen).join xx $cols).join(' ');
          #     I like this representation because the code for rows
          #     is spread out over multiple lines (vertically) and the
          #     code for a single line is horizontal (one line).
          #     In practice, it doesn't take long to get used
          #     to the left-to-right reading of Perl 6 syntax with
          #         variable.method1.method2.method3
          #     and is so much easier to read than the Perl 5 syntax of
          #         function3(function2(function1(variable)))
          #     Perl 5 allows using no parentheses but you still need
          #     to read "from the inside out" to understand what's going on.
          # )
          # I divided what I originally had into two lines to
          # make it easier for beginners to read.
          # 1. Start with the array @char.
          # 2. Choose $passlen elements at random from it (.roll might
          #    choose the same element more than once, use .pick to
          #    choose the same element no more than once).
          # 3. That gives us a new array that we join together (take spaces
          #    out of) to form one password.
          # 4.  The xx $cols gives us $cols random passwords.
          my @pass = @char.roll($passlen).join xx $cols;
          # Print the $cols passwords on one line separated by spaces.
          say @pass.join(' ');

Here are some results of running the program

  % ./t.p6 -h
    t.p6 [-d|--digits] [-p|--passlen=<Int>] [-r|--rows=<Int>] [-u|--uppercase] 

  % ./t.p6 -p=5 --rows=3
  nbmtu lrelu zeqas ptvmj ctcub axieh jsikn ilsro vuaje cybvh npoeb pfcrb jwwxi
  ynwji xpndp rgmcd oewhw dtmas pckxt wdfbm lxwtq eeltp zkkwv lamda jlvdg vbcrf
  telfq xsljq cpiik gvmes mipyx hoihp tadbs ijzeh uwqmz bmnco ixgjs iydmk yxnai

The message below explains how to get and find out more about Perl 6.


> Date: Mon, 27 Jul 2015 21:35:11 +0200
> From: Moritz Lenz <moritz at faui2k3.org>
> To: perl6-users <perl6-users at perl.org>,
>         perl6-compiler <perl6-compiler at perl.org>,
>         Perl 6 Language <perl6-language at perl.org>
> Subject: Announce: Rakudo Star Release 2015.07
> A useful, usable, "early adopter" distribution of Perl 6
> On behalf of the Rakudo and Perl 6 development teams, I'm happy to
> announce the July 2015 release of "Rakudo Star", a useful and usable
> distribution of Perl 6. The tarball for the July 2015 release is
> available from <http://rakudo.org/downloads/star/>.
> This Rakudo Star release comes with support for the MoarVM
> backend (all module tests pass on supported platforms).
> In the Perl 6 world, we make a distinction between the language
> ("Perl 6") and specific implementations of the language such as
> "Rakudo Perl". This Star release includes [release 2015.07.2] of the
> [Rakudo Perl 6 compiler], version 2015.07 of [MoarVM], plus various
> modules, documentation, and other resources collected from the
> Perl 6 community.
> [release 2015.07.2]:
>     https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.07.md
> [Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
> [MoarVM]: http://moarvm.org/
> Some of the new compiler features added to this release include:
> * Cool.substr(-rw) and &substr(-rw) now also accept a Range
> * Added trait "is required" on class attributes
> * &?ROUTINE and &?BLOCK
> * &words implemented (to completement .words)
> * Numeric comparison ops (== > etc) for DateTimes
> * samewith() now also works in subs
> * Calling the .clone method with alternate values no longer changes original
> * .grep and &grep now consume multiple elements for many-param blocks
> * ENTER phaser now can be used as an r-value
> Notable changes in modules shipped with Rakudo Star:
> * Bailador: Add links to documentation
> * DBIish: Use Postgres environment variables for test configuration
> * doc: More documentation, mostly for IO-related classes and methods
> There are some key features of Perl 6 that Rakudo Star does not yet
> handle appropriately, although they will appear in upcoming releases.
> Some of the not-quite-there features include:
>   * advanced macros
>   * non-blocking I/O (in progress)
>   * much of Synopsis 9 and 11
> There is an online resource at <http://perl6.org/compilers/features>
> that lists the known implemented and missing features of Rakudo's
> backends and other Perl 6 implementations.
> In many places we've tried to make Rakudo smart enough to inform the
> programmer that a given feature isn't implemented, but there are many
> that we've missed. Bug reports about missing and broken features are
> welcomed at <rakudobug at perl.org>.
> See <http://perl6.org/> for links to much more information about
> Perl 6, including documentation, example code, tutorials, reference
> materials, specification documents, and other supporting resources. A
> draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf in
> the release tarball.
> The development team thanks all of the contributors and sponsors for
> making Rakudo Star possible. If you would like to contribute, see
> <http://rakudo.org/how-to-help>, ask on the <perl6-compiler at perl.org>
> mailing list, or join us on IRC \#perl6 on freenode.

More information about the Purdue-pm mailing list