Lance Wicks
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
my $foo;
for (1..5) {
$foo += $_;
}
print $foo;
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
my $foo;
for (1..5) {
$foo += $_;
}
print $foo;
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
Ko te katoa o nga tangata i te whanaungatanga mai e watea ana i nga here katoa; e tauriterite ana hoki nga mana me nga tika. E whakawhiwhia ana hoki ki a ratou te ngakau whai whakaaro me te hinengaro mohio ki te tika me te he, a e tika ana kia meinga te mahi a tetahi ki tetahi me ma roto atu i te wairua o te noho tahi, ano he teina he tuakana i ringa i te whakaaro kotahi.
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
Kua anau rangatira ia te tangata katoatoa ma te aiteite i te au tikaanga e te tu ngateitei tiratiratu. Kua ki ia ratou e te mero kimi ravenga e te akavangakau e kia akono tetai i tetai, i roto i te vaerua piri anga taeake.
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl6 with Perl 5 accent
my $foo;
for (1..5) {
$foo += $_;
}
print $foo;
# Perl 6
my $foo = [+] (1..5)
print $foo;
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 5
sub area {
my %args = @_;
return $args{height} * $args{width};
}
print area(height => 5, width => 5);
# output: 25
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area {
my %args = @_;
return $args{height} * $args{width};
}
print area(height => 5, width => 5);
# output:
#===SORRY!=== Error while compiling /home/lancew/dev/lpw/loops.p6
#Variable '$args' is not declared. Did you mean '%args'?
#at /home/lancew/dev/lpw/loops.p6:5
#------> return 'yes' if ⏏$args{positive};
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area {
my %args = @_;
return %args{'height'} * %args{'width'};
}
print area('height' => 5, 'width' => 5);
# output: 25
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area {
my %args = @_;
return %args{'height'} * %args{'width'};
}
print area('height' => 5, 'width' => 5);
# output: 25
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area {
my %args = @_;
return %args{'height'} * %args{'width'};
}
print area('height' => 5, 'width' => 5);
# output: 25
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (:$height, :$width) {
return $height * $width;
}
say area(:height(5), :width(5));
# output: 25
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (:$height, :$width) {
return $height * $width;
}
say area(:height(5), :width(5));
# output: 25
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (:$height, :$width) {
return $height * $width;
}
say area(:height(5), :width(5));
# output: 25
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (:$height, :$width) {
return $height * $width;
}
say area(:height(5), :width(5));
# output: 25
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (Int :$height, Int :$width) returns Int {
return $height * $width;
}
say area(:height("foo"), :5width);
# output:
# Type check failed in binding to parameter '$height';
# expected Int but got Str ("foo")
# in sub area at loops.p6 line 2
# in block <unit> at loops.p6 line 7
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (Int :$height, Int :$width) returns Int {
return $height * $width;
}
say area(:height("foo"), :5width);
# output:
# Type check failed in binding to parameter '$height';
# expected Int but got Str ("foo")
# in sub area at loops.p6 line 2
# in block <unit> at loops.p6 line 7
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (Int :$height, Int :$width) returns Int {
return $height * $width;
}
say area(:height("foo"), :5width);
# output:
# Type check failed in binding to parameter '$height';
# expected Int but got Str ("foo")
# in sub area at loops.p6 line 2
# in block <unit> at loops.p6 line 7
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (Int :$height, Int :$width) returns Int {
return $height * $width;
}
say area(:height("foo"), :5width);
# output:
# Type check failed in binding to parameter '$height';
# expected Int but got Str ("foo")
# in sub area at loops.p6 line 2
# in block <unit> at loops.p6 line 7
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Perl 6
sub area (Int :$height, Int :$width) returns Int {
return $height * $width;
}
say area(:height("foo"), :5width);
# output:
# Type check failed in binding to parameter '$height';
# expected Int but got Str ("foo")
# in sub area at loops.p6 line 2
# in block <unit> at loops.p6 line 7
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
use strict;
use warnings;
use Function::Parameters;
use Data::Dumper;
die "Usage: ch-1.pl [N]\n" if @ARGV>1;
my $n = shift // 100;
my $percentleft = 100;
my $biggestpercent = 0;
my $guestwithbiggestpercent = 0;
foreach my $i (1..$n)
{
my $pi = $i * $percentleft / 100; # amount for guest i
print "guest $i has $pi percent of the pie\n";
if( $pi > $biggestpercent )
{
$biggestpercent = $pi;
$guestwithbiggestpercent = $i;
}
$percentleft -= $pi; # percentage left over
}
print "\nguest $guestwithbiggestpercent has biggest percentage of pie: ".
"$biggestpercent\n";
#$ perl test2.pl 5
#guest 1 has 1 percent of the pie
#guest 2 has 1.98 percent of the pie
#guest 3 has 2.9106 percent of the pie
#guest 4 has 3.764376 percent of the pie
#guest 5 has 4.5172512 percent of the pie
#
#guest 5 has biggest percentage of pie: 4.5172512
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
sub MAIN(Int $n=100) {
my $percentleft = 100;
my $biggestpercent = 0;
my $guestwithbiggestpercent = 0;
for 1..$n -> $i
{
my $pi = $i * $percentleft / 100; # amount for guest i
say "guest $i has $pi percent of the pie";
if $pi > $biggestpercent
{
$biggestpercent = $pi;
$guestwithbiggestpercent = $i;
}
$percentleft -= $pi; # percentage left over
}
say "\nguest $guestwithbiggestpercent has biggest percentage of pie: " ~
"$biggestpercent";
}
# $perl6 test2.p6 5
#guest 1 has 1 percent of the pie
#guest 2 has 1.98 percent of the pie
#guest 3 has 2.9106 percent of the pie
#guest 4 has 3.764376 percent of the pie
#guest 5 has 4.5172512 percent of the pie
#
#guest 5 has biggest percentage of pie: 4.5172512
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
sub MAIN(Int $n=100) {
my $percentleft = 100;
my $biggestpercent = 0;
my $guestwithbiggestpercent = 0;
for 1..$n -> $i
{
my $pi = $i * $percentleft / 100; # amount for guest i
say "guest $i has $pi percent of the pie";
if $pi > $biggestpercent
{
$biggestpercent = $pi;
$guestwithbiggestpercent = $i;
}
$percentleft -= $pi; # percentage left over
}
say "\nguest $guestwithbiggestpercent has biggest percentage of pie: " ~
"$biggestpercent";
}
# $perl6 test2.p6 5
#guest 1 has 1 percent of the pie
#guest 2 has 1.98 percent of the pie
#guest 3 has 2.9106 percent of the pie
#guest 4 has 3.764376 percent of the pie
#guest 5 has 4.5172512 percent of the pie
#
#guest 5 has biggest percentage of pie: 4.5172512
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
sub MAIN(Int $n=100) {
my $percentleft = 100;
my $biggestpercent = 0;
my $guestwithbiggestpercent = 0;
for 1..$n -> $i
{
my $pi = $i * $percentleft / 100; # amount for guest i
say "guest $i has $pi percent of the pie";
if $pi > $biggestpercent
{
$biggestpercent = $pi;
$guestwithbiggestpercent = $i;
}
$percentleft -= $pi; # percentage left over
}
say "\nguest $guestwithbiggestpercent has biggest percentage of pie: " ~
"$biggestpercent";
}
# $perl6 test2.p6 5
#guest 1 has 1 percent of the pie
#guest 2 has 1.98 percent of the pie
#guest 3 has 2.9106 percent of the pie
#guest 4 has 3.764376 percent of the pie
#guest 5 has 4.5172512 percent of the pie
#
#guest 5 has biggest percentage of pie: 4.5172512
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
sub MAIN(Int $n=100) {
my $percentleft = 100;
my $biggestpercent = 0;
my $guestwithbiggestpercent = 0;
for 1..$n -> $i
{
my $pi = $i * $percentleft / 100; # amount for guest i
say "guest $i has $pi percent of the pie";
if $pi > $biggestpercent
{
$biggestpercent = $pi;
$guestwithbiggestpercent = $i;
}
$percentleft -= $pi; # percentage left over
}
say "\nguest $guestwithbiggestpercent has biggest percentage of pie: " ~
"$biggestpercent";
}
# $perl6 test2.p6 5
#guest 1 has 1 percent of the pie
#guest 2 has 1.98 percent of the pie
#guest 3 has 2.9106 percent of the pie
#guest 4 has 3.764376 percent of the pie
#guest 5 has 4.5172512 percent of the pie
#
#guest 5 has biggest percentage of pie: 4.5172512
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
sub MAIN(Int $n=100) {
my ($topguest, $topshare) = (1 .. $n).map({
state $pie = 100.0;
my $share = $pie * ($_ * 0.01);
$pie -= $share;
$_ => $share;
})
.max( *.value )
.kv;
say "Guest $topguest gets ", $topshare, '% of the pie.';
}
# $perl6 test2_map.p6 5
#
# Guest 5 gets 4.5172512% of the pie.
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
sub MAIN(Int $n=100) {
my ($topguest, $topshare) = (1 .. $n).map({
state $pie = 100.0;
my $share = $pie * ($_ * 0.01);
$pie -= $share;
$_ => $share;
})
.max( *.value )
.kv;
say "Guest $topguest gets ", $topshare, '% of the pie.';
}
# $perl6 test2_map.p6 5
#
# Guest 5 gets 4.5172512% of the pie.
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
sub MAIN(Int $n=100) {
my ($topguest, $topshare) = (1 .. $n).map({
state $pie = 100.0;
my $share = $pie * ($_ * 0.01);
$pie -= $share;
$_ => $share;
})
.max( *.value )
.kv;
say "Guest $topguest gets ", $topshare, '% of the pie.';
}
# $perl6 test2_map.p6 5
#
# Guest 5 gets 4.5172512% of the pie.
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
sub MAIN(Int $n=100) {
my ($topguest, $topshare) = (1 .. $n).map({
state $pie = 100.0;
my $share = $pie * ($_ * 0.01);
$pie -= $share;
$_ => $share;
})
.max( *.value )
.kv;
say "Guest $topguest gets ", $topshare, '% of the pie.';
}
# $perl6 test2_map.p6 5
#
# Guest 5 gets 4.5172512% of the pie.
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Lingua::Postcodes
sub name {
my $country_code = shift;
if ( @_ == 0 ) {
return unless exists $POSTCODES{$country_code};
return $POSTCODES{$country_code}{'EN'};
}
else {
my $language = shift;
return unless exists $POSTCODES{$country_code}{$language};
return $POSTCODES{$country_code}{$language};
}
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Lingua::Postcodes (PERL 6)
multi sub name ($country_code) is export(:name) {
return unless %POSTCODES{$country_code}:exists;
return %POSTCODES{$country_code}{'EN'};
}
multi sub name ($country_code, $language) is export(:name) {
return unless %POSTCODES{$country_code}{$language}:exists;
return %POSTCODES{$country_code}{$language};
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Lingua::Postcodes (PERL 6)
multi sub name ($country_code) is export(:name) {
return unless %POSTCODES{$country_code}:exists;
return %POSTCODES{$country_code}{'EN'};
}
multi sub name ($country_code, $language) is export(:name) {
return unless %POSTCODES{$country_code}{$language}:exists;
return %POSTCODES{$country_code}{$language};
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Lingua::Postcodes (PERL 6)
multi sub name ($country_code) is export(:name) {
return unless %POSTCODES{$country_code}:exists;
return %POSTCODES{$country_code}{'EN'};
}
multi sub name ($country_code, $language) is export(:name) {
return unless %POSTCODES{$country_code}{$language}:exists;
return %POSTCODES{$country_code}{$language};
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Lingua::Postcodes (PERL 6)
multi sub name ($country_code) is export(:name) {
return unless %POSTCODES{$country_code}:exists;
return %POSTCODES{$country_code}{'EN'};
}
multi sub name ($country_code, $language) is export(:name) {
return unless %POSTCODES{$country_code}{$language}:exists;
return %POSTCODES{$country_code}{$language};
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Leftpad by Dave Golden
sub leftpad {
no warnings 'uninitialized';
return "" . $_[0] if $_[1] < 1;
return sprintf( "%*s", $_[1], $_[0] ) unless defined $_[2] && length $_[2];
return substr( $_[2], 0, 1 ) x ( $_[1] - length $_[0] ) . $_[0];
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Leftpad by Dave Golden in Perl 6
sub leftpad ($text, $pad?, $char?) is export {
return "" ~ $text if $pad < 1;
return sprintf( "%*s", $pad, $text.defined ?? $text.Str !! " " )
unless $char.defined && $char.elems;
return $char.Str x ($pad - $text.elems ) ~ $text;
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Leftpad by Dave Golden in Perl 6
sub leftpad ($text, $pad?, $char?) is export {
return "" ~ $text if $pad < 1;
return sprintf( "%*s", $pad, $text.defined ?? $text.Str !! " " )
unless $char.defined && $char.elems;
return $char.Str x ($pad - $text.elems ) ~ $text;
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Leftpad by Dave Golden in Perl 6
sub leftpad ($text, $pad?, $char?) is export {
return "" ~ $text if $pad < 1;
return sprintf( "%*s", $pad, $text.defined ?? $text.Str !! " " )
unless $char.defined && $char.elems;
return $char.Str x ($pad - $text.elems ) ~ $text;
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Leftpad by Dave Golden in Perl 6
sub leftpad ($text, $pad?, $char?) is export {
return "" ~ $text if $pad < 1;
return sprintf( "%*s", $pad, $text.defined ?? $text.Str !! " " )
unless $char.defined && $char.elems;
return $char.Str x ($pad - $text.elems ) ~ $text;
}
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
# Based on https://www.perl.com/article/fork-yeah-/
for (1..5) {
my $pid = fork;
die "failed to fork: $!" unless defined $pid;
next if $pid;
sleep 5 - int(rand($_));
print "$_\n";
exit;
}
my $kid;
do {
$kid = waitpid -1, 0;
} while ($kid > 0);
# 3
# 4
# 2
# 1
# 5
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
await do for 1..5 -> $i {
start {
sleep (1..$i).pick;
say $i;
}
}
# 1
# 3
# 4
# 2
# 5
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
await do for 1..5 -> $i {
start {
sleep (1..$i).pick;
say $i;
}
}
# 1
# 3
# 4
# 2
# 5
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
await do for 1..5 -> $i {
start {
sleep (1..$i).pick;
say $i;
}
}
# 1
# 3
# 4
# 2
# 5
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
await do for 1..5 -> $i {
start {
sleep (1..$i).pick;
say $i;
}
}
# 1
# 3
# 4
# 2
# 5
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
say 0.1 + 0.2 - 0.3
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
say print (0.1 + 0.2 - 0.3);
5.55111512312578e-17
say (0.1 + 0.2 - 0.3);
0
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪
say Date.today;
say Date.today.later(month => 1);
say Date.today.later(:month);
# 2019-10-16
# 2019-11-16
# 2019-11-16
»ö« Perl 6, Losing your Perl 5 Accent - Lance Wicks - LPW2019 🐪