SlideShare a Scribd company logo
6 more
things
about 6
Boston.pm, 10 Jan 2017
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
perlmodules.net
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
Rats
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
$ perl -le 'print 0.3 - 0.2- 0.1'
-2.77555756156289e-17
$ perl6 -e 'put 0.3 - 0.2 - 0.1'
0
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
$ perl6
To exit type 'exit' or '^D'
> 0.1
0.1
> 0.1.^name
Rat
> 0.1.numerator
1
> 0.1.denominator
10
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
$ perl6
To exit type 'exit' or '^D'
> 1/3 + 1/4
0.583333
> (1/3 + 1/4).denominator
12
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
Soft Failures
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
CATCH {
default { put "Caught something" }
}
my $fh = open 'not-there'; # this fails
put "Result is " ~ $fh.^name;
unless $fh { # $fh.so
given $fh.exception {
put "failure: {.^name}: {.message}";
}
}
Result is Failure
failure: X::AdHoc: Failed to open file
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
Resume
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
{
CATCH {
default {
put "Caught {.^name}: {.message}" }
}
my $fh = open 'not-there', :r;
my $line = $fh.line;
put "I'm still going";
}
Caught X::AdHoc: Failed to open file
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
{
CATCH {
default {
put "Caught {.^name}: {.message}";
.resume
}
}
my $fh = open 'not-there', :r;
my $line = $fh.line;
put "I'm still going";
}
Caught X::AdHoc: Failed to open file
I’m still going
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
Interpolation
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my $scalar = 'Hamadryas';
my @array = qw/ Dog Cat Bird /;
my %hash = a => 1, b => 2, c => 3;
put "scalar: $scalar";
put "array: @array[]";
put "hash: %hash{}";
scalar: Hamadryas
array: Dog Cat Bird
hash: a 1
b 2
c 3
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
$_ = 'Hamadryas';
put "scalar: { $_ }";
put "scalar: { 1 + 2 }";
put "scalar: { .^name }";
scalar: Hamadryas
scalar: 3
scalar: Str
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
fmt
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my $s = <22/7>;
put $s.fmt( '%5.4f' );
put $s.fmt( '%.14f' );
3.1429
3.14285714285714
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @s = 1 .. 8;
@s
.map(
(*/7).fmt('%.5f')
)
.join( "n" ).put;
0.14286
0.28571
0.42857
0.57143
0.71429
0.85714
1.00000
1.14286
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
Lists of Lists
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my $scalar = ( 1, 2, 3 );
# my $scalar = 1, 2, 3; # Nope!
put "scalar: $scalar";
put "scalar: { $scalar.^name }";
scalar: 1 2 3
scalar: List
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @array = ( ( 1, 2 ), qw/a b/ );
put "elems: { @array.elems }";
put "@array[]";
put "@array[0]";
put "{ @array[0].^name }";
2
1 2 a b
1 2
List
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my $x = ( 1, 2, 6 );
some_sub( $x );
sub some_sub ( $x ) {
put "x has { $x.elems }";
}
x has 3
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my Buf $buf =
Buf.new( 0xDE, 0xAD, 0xBE, 0xEF );
for $buf.values -> $c {
put "c is $c";
}
c is 222
c is 173
c is 190
c is 239
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my Buf $buf =
Buf.new( 0xDE, 0xAD, 0xBE, 0xEF );
for $buf.rotor(2) -> $c {
put "c is $c";
}
c is 222 173
c is 190 239
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my Buf $buf =
Buf.new( 0xDE, 0xAD, 0xBE, 0xEF );
for $buf.rotor(2) -> $c {
put "c is $c";
put "word is ",
( $c[0] +< 8 + $c[1] )
.fmt( '%02X' );
}
c is 222 173
word is DEAD
c is 190 239
word is BEEF
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @a = 'a', ('b', 'c' );
my @b = 'd', 'e', 'f', @a;
my @c = 'x', $( 'y', 'z' ), 'w';
my @ab = @a, @b, @c;
say "ab: ", @ab;
ab: [[a (b c)] [d e f [a (b c)]]
[x (y z) w]]
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @f = @ab;
while @f.grep: *.elems > 1 {
@f = @f.map: *.Slip;
};
( a b c d e f a b c x y z w )
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @f = @ab;
@f = slippery( @f );
sub slippery ( $l, $level = 0 ) {
put "t" x $level, "Got ", $l;
my @F;
for $l.list {
when .elems == 1 { push @F, $_ }
default {
push @F, slippery($_,$level + 1 ) }
}
@F.Slip;
}
( a b c d e f a b c x y z w )
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @f = @ab;
my @f2;
while @f {
@f[0].elems == 1 ??
@f2.push( @f.shift )
!!
@f.unshift( @f.shift.Slip )
}
( a b c d e f a b c x y z w )
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @f = @ab;
@f = gather slippery( @f );
sub slippery ( $l ) {
for $l.list {
say "Processing $_";
.elems == 1
?? take $_ !! slippery( $_ );
}
( a b c d e f a b c x y z w )
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
my @f = @ab;
@f = gather {
while @f {
@f[0].elems == 1 ??
take @f.shift
!!
@f.unshift( @f.shift.Slip )
}
}
( a b c d e f a b c x y z w )
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6 sub prefix:<__>( $listy ) {
gather {
while @f {
@f[0].elems == 1 ??
take @f.shift
!!
@f.unshift( @f.shift.Slip )
}
}
}
my @f = @ab;
@f = __@f;
( a b c d e f a b c x y z w )
ThePerlReview•www.theperlreview.com
6MoreThingsAbout6
Questions

More Related Content

PDF
6 things about perl 6
PDF
Dumping Perl 6 (French Perl Workshop)
PDF
Perl v5.26 Features (AmsterdamX.pm)
PDF
Dumping Perl 6 (AmsterdamX.pm)
PDF
Perl 5.28 new features
PDF
PrettyDump Perl 6 (London.pm)
PDF
Perl Bag of Tricks - Baltimore Perl mongers
PDF
Perl 6 by example
6 things about perl 6
Dumping Perl 6 (French Perl Workshop)
Perl v5.26 Features (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)
Perl 5.28 new features
PrettyDump Perl 6 (London.pm)
Perl Bag of Tricks - Baltimore Perl mongers
Perl 6 by example

What's hot (20)

PDF
I, For One, Welcome Our New Perl6 Overlords
PDF
Melhorando sua API com DSLs
PDF
Perl6 grammars
PDF
20 modules i haven't yet talked about
PDF
The Magic Of Tie
PDF
The Perl6 Type System
PDF
Perl6 in-production
PDF
Bag of tricks
PDF
Advanced modulinos trial
PDF
Text in search queries with examples in Perl 6
PDF
Advanced modulinos
KEY
SPL, not a bridge too far
PDF
Parsing JSON with a single regex
PDF
TDDBC お題
PDF
Introduction to Perl
PDF
Learning Perl 6
KEY
10 Catalyst Tips
PDF
R版Getopt::Longを作ってみた
I, For One, Welcome Our New Perl6 Overlords
Melhorando sua API com DSLs
Perl6 grammars
20 modules i haven't yet talked about
The Magic Of Tie
The Perl6 Type System
Perl6 in-production
Bag of tricks
Advanced modulinos trial
Text in search queries with examples in Perl 6
Advanced modulinos
SPL, not a bridge too far
Parsing JSON with a single regex
TDDBC お題
Introduction to Perl
Learning Perl 6
10 Catalyst Tips
R版Getopt::Longを作ってみた
Ad

Viewers also liked (10)

PDF
Perl Power Tools - Saint Perl 6
PDF
Create and upload your first Perl module to CPAN
PDF
Tour of the Perl docs
PDF
I ❤ CPAN
PDF
The Surprisingly Tense History of the Schwartzian Transform
PDF
Making My Own CPAN
PDF
Making My Own CPAN
PDF
The Whitespace in the Perl Community
PDF
CPAN Workshop, Chicago 2014
PDF
Perl Conferences for Beginners
Perl Power Tools - Saint Perl 6
Create and upload your first Perl module to CPAN
Tour of the Perl docs
I ❤ CPAN
The Surprisingly Tense History of the Schwartzian Transform
Making My Own CPAN
Making My Own CPAN
The Whitespace in the Perl Community
CPAN Workshop, Chicago 2014
Perl Conferences for Beginners
Ad

Similar to 6 more things about Perl 6 (20)

KEY
Good Evils In Perl (Yapc Asia)
PDF
Perl programming language
ODP
Perl Introduction
PDF
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
ODP
What's new in Perl 5.10?
PDF
Introduction to writing readable and maintainable Perl
PDF
perl 6 hands-on tutorial
PDF
What's New in Perl? v5.10 - v5.16
ODP
Introduction to Perl - Day 1
PPT
PERL.ppt
PDF
Good Evils In Perl
PDF
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
PDF
Modern Perl for Non-Perl Programmers
PDF
Introducing perl6
ODP
Advanced Perl Techniques
ODP
Whatsnew in-perl
ODP
Intermediate Perl
ODP
Introduction to Perl
PPTX
Lecture 3 Perl & FreeBSD administration
Good Evils In Perl (Yapc Asia)
Perl programming language
Perl Introduction
Introduction to Writing Readable and Maintainable Perl (YAPC::EU 2011 Version)
What's new in Perl 5.10?
Introduction to writing readable and maintainable Perl
perl 6 hands-on tutorial
What's New in Perl? v5.10 - v5.16
Introduction to Perl - Day 1
PERL.ppt
Good Evils In Perl
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Modern Perl for Non-Perl Programmers
Introducing perl6
Advanced Perl Techniques
Whatsnew in-perl
Intermediate Perl
Introduction to Perl
Lecture 3 Perl & FreeBSD administration

More from brian d foy (9)

PDF
Conferences for Beginners presentation
PDF
20 years in Perl
PDF
Reverse Installing CPAN
PDF
Backward to DPAN
PDF
Perl docs {sux|rulez}
PDF
Why I Love CPAN
PDF
What's wrong with the perldocs
PDF
Frozen Perl 2011 Keynote
PDF
brian d foy
Conferences for Beginners presentation
20 years in Perl
Reverse Installing CPAN
Backward to DPAN
Perl docs {sux|rulez}
Why I Love CPAN
What's wrong with the perldocs
Frozen Perl 2011 Keynote
brian d foy

Recently uploaded (20)

PPTX
A Presentation on Touch Screen Technology
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Mushroom cultivation and it's methods.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Hybrid model detection and classification of lung cancer
PPTX
Tartificialntelligence_presentation.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
August Patch Tuesday
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
A Presentation on Touch Screen Technology
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Web App vs Mobile App What Should You Build First.pdf
Mushroom cultivation and it's methods.pdf
Programs and apps: productivity, graphics, security and other tools
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
1 - Historical Antecedents, Social Consideration.pdf
Hybrid model detection and classification of lung cancer
Tartificialntelligence_presentation.pptx
MIND Revenue Release Quarter 2 2025 Press Release
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
A Presentation on Artificial Intelligence
August Patch Tuesday
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
NewMind AI Weekly Chronicles - August'25-Week II
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...

6 more things about Perl 6