[Purdue-pm] example Perl 6 program

Mark Senn mark at purdue.edu
Fri Feb 5 05:38:00 PST 2016


Purdue Perl Mongers, here is an example Perl 6 program that runs on my
Red Hat Linux computer using Rakudo Star 2016.01.  Thought you might be
interested.  You may want to rewrite this in Perl 5 to see if you like
Perl 5 or Perl 6 better (I much prefer Perl 6).  -mark

#!/home/pier/e/mark/bin/perl6

# Give an error message if we aren't using the right version of Perl.
use v6c;

# The data.txt file is
#     10
#     20
#     30
# without the "#     " at the beginning of the lines.
my @x = lines slurp 'data.txt';

# This prints
#     3 numbers, average is 20
say @x.elems, " numbers, average is ", ([+] @x) / @x.elems;

# Print same output using {...} to interpolate expressions in quotes.
say "{@x.elems} numbers, average is {([+] @x) / @x.elems}";


More information about the Purdue-pm mailing list