SlideShare a Scribd company logo
1 of 81
Learning Perl 6
     brian d foy, brian@stonehenge.com
 Randal L. Schwartz, merlyn@stonehenge.com
       Version 0.5, YAPC Chicago 2006
for the purposes of this tutorial




 Perl 5
 never
existed
Don’t really do this
$ ln -s /usr/local/bin/pugs /usr/bin/perl
Allison, Audrey,
      Damian, and
          Larry...
The Apple Store on Michigan Avenue is giving away free
          MacBooks for the next 90 minutes

take the Red Line up to Chicago then walk towards the lake
Introduction

It’s a completely new language
That other one never existed
Llama 6 is a long way off
This is the basics of the language
Next week it might be different
Basis for this talk
Apocalypses
Exegeses
Synopses
Perl6-Pugs-N-NN
 docs/quickref/data
 examples/
Actual Pugs behavior
Writing programs
you can actually
      run
We’re liars

There’s not enough time for everything
We can’t tell you the whole story
There are other ways to do things
Damian gave you the Perl 6 update just now
 We wrote these slides last week
In 80 minutes, we can cover

   Data
   Variables
   Control structures
   Input / Output
If we had more time

Subroutines
Regular expressions
Using modules
Creating classes, objects, &c.
Q & A at the end
just find Damian in the hallway
Try this at home
not at work
Getting Pugs

http://www.pugscode.org
Needs Glasgow Haskell Compiler (GHC)
Get the binary builds
 compilation can take a long, long time
 and it eats up your CPU
Making a P6 program
Programs are just text files
Syntax is C like, mostly
 whitespace is not significant, mostly
 statements separated by semicolons
 comments are # to end of line

Use pugs on the shebang line
 #!/usr/local/bin/pugs
 say quot;Hello Worldquot;;
Objects & Methods
Data are objects or nouns
Methods are verbs (actions)
Object.Method

 #!/usr/local/bin/pugs

 quot;Hello Worldquot;.say;
Run from command line
  $ pugs hello.p6
  Hello World

  $ ./hello.p6
  Hello World

  $ pugs -e 'say quot;Hello Worldquot;'
  Hello World

  $ pugs
  pugs> say quot;Hello Worldquot;
  Hello World
  bool::true
Scalars
Scalars are single values

        Numbers

         Strings

        Boolean
Literal numbers
3 3.14 3.14e7 -4.56 0

       123_456

       0b0110

     0o377 0o644

  0xAB 0xDEAD_BEEF
say
say can be used a method
Outputs the value and tacks on a newline
More output stuff later

   quot;Hello Worldquot;.say;

   say quot;Hello Worldquot;;
Arithmetic

2   + 3           5
2   - 3           -1
2   * 3           6
2   / 3           0.66666666...
2   ** 3          8
2   % 3           2
Method call forms
# indirect form
say 3;

# direct form
3.say;

# parens to group
( 10 / 3 ).say;

# / really just a method
(10./(3)).say;
Strings


Sequence of zero or more characters
Perl inter-converts automatically with
numbers
Single quoted strings
'Hello World'.say;

'I said 'Hello World!''.say;

'I need a literal '.say;

q/I don't need to escape/.say;
Double quoted strings
quot;HellotWorldquot;.say;

quot;I said quot;Hello World!quot;quot;.say;

quot;Hello Worldquot;.print; # no newline

quot;Hello Worldnquot;.print;

qq/Hello Worldn/.print;
String concatenation
   ~ stitches strings together
( quot;Helloquot; ~ quot;Worldquot; ).say;
HelloWorld

( quot;Helloquot; ~ quot; quot; ~ quot;Worldquot; ).say;
Hello World
String replication
      x repeats and joins string
( quot;Hiquot; x 3 ).say;        HiHiHi

( quot;Hiquot; x 2.5 ).say;      floor - HiHi

( quot;Hiquot; x -1 ).say;       error!
Booleans


True or False, Yes or No, On or Off, 1 or nothing
Often the result of a comparison
Numeric comparisons
5    <   6   True
5    >   6   False
5   ==   6   False
5   <=   6   True
5   >=   6   False
5   !=   6   True
String comparisons

'fred'   lt   'barney'   False
'fred'   gt   'barney'   True
'fred'   eq   'barney'   False
'fred'   le   'barney'   False
'fred'   ge   'barney'   True
'fred'   ne   'barney'   True
Scalar variables
Stores a single value
Name starts with a letter or underscore,
followed by letters, underscores, or digits
Has a special symbol (sigil) prepended, $
Starts off undefined (absence of value)
We have to assign it a value
Declare with my on first use
Scalar Assignment

my $num = 5;
quot;The number is $numquot;.say;

my $str = quot;Pugsquot;;
quot;Just another $str hacker, quot;.say;
Scalar value type
The ref method gives the type of scalar
 my   $s1   =   5 < 6;
 my   $s2   =   quot;Perlquot;;
 my   $s3   =   6 - 5;
 my   $s4   =   3.14;

 $s1.ref.say;              Bool
 $s2.ref.say;              Str
 $s3.ref.say;              Int
 $s4.ref.say;              Rat
Standard input

quot;Enter a name> quot;.print;
my $input = (=$*IN).chomp;

quot;Enter another name> quot;.print;
$input = (=<>).chomp;
Control Structures
if-elsif-else
if 5 < 6   { quot;5 less than 6quot;.say }


if 5 > 6   { quot;5 more than 6quot;.say }
else       { quot;5 not more than 6quot;.say }


if 5 < 4    { quot;5 less than 4quot;.say }
elsif 5 > 4 { quot;5 more than 4quot;.say }
else        { quot;5 not more than 4quot;.say }
Complex comparisons
if( 5 < $x < 10 )
  {
  quot;$x is between 5 and 10quot;.say
  }
else
  {
  quot;$x is not between 5 and 10quot;.say
  }
Junctions
my $num   = 5;

if( $num == any( <5 6 7> ) )
  {
  quot;$num is in the setquot;.say
  }
else
  {
  quot;$num is not in the setquot;.say
  }
Expression modifiers
Apply a condition to a single expression

quot;5 is greaterquot;.say if 5 > 6;

quot;5 is lessquot;.say if 5 < 6;
loop
loop ( init; test; increment ){ }

loop ( $i = 1; $i < 10; $i++ ) {
  quot;I can count to $iquot;.say;
  }
   I can   count   to   1
   I can   count   to   2
   I can   count   to   3
   I can   count   to   4
   ...
next
   skips the rest of the block
   goes to next iteration
loop ( $i = 1;    $i < 10; $i++ ) {
  next if $i %    2;
  quot;I can count    to $iquot;.say;
  }
   I can count    to   2
   I can count    to   4
   I can count    to   6
   I can count    to   8
last
   skips the rest of the iterations
   continues after the loop
loop ( $i = 1; $i < 10; $i++ ) {
  last if $i == 5;
  quot;I can count to $iquot;.say;
  }
   I can count to 2
   I can count to 4
   I can count to 6
   I can count to 8
redo
   starts the current iteration again
   uses the same element (if any)

loop {
  quot;Do you like pugs?> quot;.print;
  my $answer = (=$*IN).chomp;

  redo if $answer ne 'yes';
  last;
  }
Number guesser
quot;Guess secret number from 1 to 10quot;.say;
my $secret = rand(10+1).int;

loop {
  quot;Enter your guess> quot;.print;
    my $guess = (=$*IN).chomp;

  if $guess < $secret
    { quot;Too low!quot;.say;    redo }
  elsif $guess > $secret
    { quot;Too high!quot;.say; redo }
  else
    { quot;That's it!quot;.say; last }
  }
Lists & Arrays
Literal Lists
( 1, 2, 3, 4 )

  <a b c d>

 my $x = 'baz'
<<foo bar $x>>
  «foo bar $x»

  ( 1 .. 3 )
( 'a' .. 'z' )
List replication
'f'   xx 4       <f f f f>

<g> xx 6         <g g g g g g>

< a b c > xx 2   < a b c a b c >
Joining elements

<1 2 3 4>.join(' ')   1 2 3 4

<1 3 5 7>.join(':')   1:3:5:7
Ranges
( 4 .. 7 )           < 4 5 6 7 >

( 'a' .. 'e' )       < a b c d e >

reverse 1 .. 3       < 3 2 1 >

( 1 .. 3 ).reverse   < 3 2 1 >
Arrays
Array variables store multiple scalars
Indexes list with integers, starting at 0
Same variable naming rules as a scalar
Special character is @ (think @rray)
Name comes from a separate namespace
Nothing to do with scalar of same name
Array assignment

my @a = < a b c >;

my @a = << a b $c >>

my @a = 1 .. 6;
Bounds
my @r = 37..42;
say quot;Minimum is quot; ~ @r.min;
say quot;Maximum is quot; ~ @r.max;

my @a = < 3 5 9 2 5 0 1 8 4 >;
say quot;Minimum is quot; ~ @a.min;
say quot;Maximum is quot; ~ @a.max;
Array elements
my @a = <a b c d e f g>;

my $first = @a[0];         a

my $last   = @a[-1];       g

my $count = @a.elems;      7

my @slice = @a[0,-1];      < a g >
Unique elements


my @a = <a b c a b d b d>;

my @b = @a.uniq;   < a b c d >
Hyperoperators
    Apply operator pair wise
my @nums   =       1 .. 10;
my @alphas =      'a' .. 'j';

my @stitch = @nums >>~<< @alphas;
< 1a 2b 3c 4d 5e 6f 7g 8h 9i 10j >
my @square = @nums >>*<< @nums;
< 1 4 9 16 25 36 49 64 81 100 >
for
for 1 .. 5 -> $elem {
  quot;I saw $elemquot;.say;
  }

      I   saw   1
      I   saw   2
      I   saw   3
      I   saw   4
      I   saw   5
for
for @ARGS -> $arg {
  quot;I saw $arg on the command linequot;.say;
  }


  I saw fred on the command line
  I saw barney on the command line
  I saw betty on the command line
Hashes
Hash variables
Hash variables stores unordered pairs
Index is the “key”, a unique string
Makes a map from one thing to another
Same naming rules as scalar and array
Special character is % (think %hash)
Name comes from a separate namespace
Nothing to do with scalar, array of same name
Hash elements
my %h = <a 5 b 7 c 3>;

my $a_value = %h{'a'};    5

my $b_value = %h<b>;      7

my $count = %h.elems;     3

my @values = %h{ <b c> }; < 7 3 >

my @values = %h<b c>;     < 7 3 >
my %hash = (
  'fred'   => 'flintstone',
  'barney' => 'rubble',
  );

%hash.say;
  barney rubblefred flintstone
%hash.join(quot;nquot;).say;
  barney rubble
  fred flintstone
Hash keys
my %hash = (
  'fred'   => 'flintstone',
  'barney' => 'rubble',
  );

for %hash.keys -> $key {
  quot;$key: %hash{$key}quot;.say;
  }
 barney: rubble
 fred: flintstone
Hash values
my %hash = (
  'fred'   => 'flintstone',
  'barney' => 'rubble',
  );

for %hash.values -> $value {
  quot;One value is $valuequot;.say;
  }
 One value is rubble
 One value is flintstone
By pairs
my %hash = (
  'fred'   => 'flintstone',
  'barney' => 'rubble',
  );

for %hash.kv -> $key, $value {
  quot;$key ---> $valuequot;.say;
  }
 barney ---> rubble
 fred ---> flintstone
Counting words
my %words;

for =<> -> $line {
  for $line.chomp.split -> $word {
    %words{$word}++;
    }
  }

for %words.kv -> $k, $v {
  quot;$k: $vquot;.say
  }
exists
      True if the key is in the hash
      Does not create the key

my @chars = <fred wilma barney betty>;

my %hash = (
  'fred'   => 'flintstone',
  'barney' => 'rubble',
  );

for @chars -> $char {
  quot;$char existsquot;.say if %hash.exists($char);
  }
delete
    Removes pair from hash
my %hash =   (
  'fred'     => 'flintstone',
  'barney'   => 'rubble',
  'dino'     => undef,
  );

%hash.delete('dino');
%hash.join(quot;nquot;).say;


  barney rubble
  fred flintstone
Input
Output
Standard input
quot;Enter a name> quot;.print;
my $input = (=$*IN).chomp;

quot;Enter another name> quot;.print;
$input = (=<>).chomp;
File input operator
The =<> reads from files from the
command line arguments

  for =<> -> $line {
    quot;Got $linequot;.print;
    }
Opening files to read
my $fh = open( $file, :r );

for =$fh -> $line {
  quot;Got $linequot;.print;
  }
Die-ing
my $file = quot;not_therequot;;

my $fh = open( quot;not_therequot;, :r )
  err die quot;Couldn’t open $file: $!quot;;

for =$fh -> $line {
  quot;Got $linequot;.print;
  }
try
     Catches exceptions

try {
  die quot;I'm dyingquot; if time.int % 2;
  quot;I made itquot;.say;
  };

quot;Error was $!quot;.say if $!;
Standard filehandles
    Default filehandles $*OUT and $*ERR


$*ERR.say( quot;This goes to stderrquot; );

$*OUT.say( quot;This goes to stdoutquot; );
Writing to files
my $file = quot;not_therequot;;

my $fh = open( quot;not_therequot;, :w )
  err die quot;Couldn’t open $file: $!quot;;

print $fh: @stuff;
# $fh.print( @stuff );
try
     Catches exceptions

try {
  die quot;I'm dyingquot; if time.int % 2;
  quot;I made itquot;.say;
  };

quot;Error was $!quot;.say if $!;
Files and Directories
File tests
     As with test(1)

my $file = quot;file_tests.p6quot;;

quot;Found filequot;.say if -e $file;
quot;Found readable filequot;.say if -r $file;

my $file_size = -s $file;

quot;File size is $file_sizequot;.say;
Other topics
given is like C’s switch (but better)

variable value types

complex data structures

regular expressions - PCRE and new stuff

sorting, string manipulation etc.

subroutines have better calling conventions
Summary

Perl 6 is a new language
It borrows from Perl (and ancestors)
It’s not done yet, but it’s almost usable

More Related Content

What's hot

The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type Systemabrummett
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tiebrian d foy
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6Andrew Shitov
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16Ricardo Signes
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolveXSolve
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)brian d foy
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Contextlichtkind
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLsAugusto Pascutti
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smartlichtkind
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev AssistantDave Cross
 

What's hot (20)

The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
 

Similar to Perl 6 basics in 80 minutes

Similar to Perl 6 basics in 80 minutes (20)

Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
PHP_Lecture.pdf
PHP_Lecture.pdfPHP_Lecture.pdf
PHP_Lecture.pdf
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
PHP-01-Overview.ppt
PHP-01-Overview.pptPHP-01-Overview.ppt
PHP-01-Overview.ppt
 
PHP-Overview.ppt
PHP-Overview.pptPHP-Overview.ppt
PHP-Overview.ppt
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Cleancode
CleancodeCleancode
Cleancode
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Scripting3
Scripting3Scripting3
Scripting3
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Introduction to Perl - Day 2
Introduction to Perl - Day 2Introduction to Perl - Day 2
Introduction to Perl - Day 2
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Lecture19-20
Lecture19-20Lecture19-20
Lecture19-20
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Perl Presentation
Perl PresentationPerl Presentation
Perl Presentation
 

More from brian d foy

Conferences for Beginners presentation
Conferences for Beginners presentationConferences for Beginners presentation
Conferences for Beginners presentationbrian d foy
 
20 years in Perl
20 years in Perl20 years in Perl
20 years in Perlbrian d foy
 
PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)brian d foy
 
Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)brian d foy
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)brian d foy
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)brian d foy
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about Perl 6brian d foy
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6brian d foy
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new featuresbrian d foy
 
The Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian TransformThe Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian Transformbrian d foy
 
Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6brian d foy
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Communitybrian d foy
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014brian d foy
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPANbrian d foy
 
Tour of the Perl docs
Tour of the Perl docsTour of the Perl docs
Tour of the Perl docsbrian d foy
 
Create and upload your first Perl module to CPAN
Create and upload your first Perl module to CPANCreate and upload your first Perl module to CPAN
Create and upload your first Perl module to CPANbrian d foy
 
Perl Conferences for Beginners
Perl Conferences for BeginnersPerl Conferences for Beginners
Perl Conferences for Beginnersbrian d foy
 
Backward to DPAN
Backward to DPANBackward to DPAN
Backward to DPANbrian d foy
 
Perl docs {sux|rulez}
Perl docs {sux|rulez}Perl docs {sux|rulez}
Perl docs {sux|rulez}brian d foy
 

More from brian d foy (20)

Conferences for Beginners presentation
Conferences for Beginners presentationConferences for Beginners presentation
Conferences for Beginners presentation
 
20 years in Perl
20 years in Perl20 years in Perl
20 years in Perl
 
PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)
 
Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about Perl 6
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new features
 
The Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian TransformThe Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian Transform
 
Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Community
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
 
I ❤ CPAN
I ❤ CPANI ❤ CPAN
I ❤ CPAN
 
Tour of the Perl docs
Tour of the Perl docsTour of the Perl docs
Tour of the Perl docs
 
Create and upload your first Perl module to CPAN
Create and upload your first Perl module to CPANCreate and upload your first Perl module to CPAN
Create and upload your first Perl module to CPAN
 
Perl Conferences for Beginners
Perl Conferences for BeginnersPerl Conferences for Beginners
Perl Conferences for Beginners
 
Backward to DPAN
Backward to DPANBackward to DPAN
Backward to DPAN
 
Perl docs {sux|rulez}
Perl docs {sux|rulez}Perl docs {sux|rulez}
Perl docs {sux|rulez}
 

Recently uploaded

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 

Perl 6 basics in 80 minutes

  • 1. Learning Perl 6 brian d foy, brian@stonehenge.com Randal L. Schwartz, merlyn@stonehenge.com Version 0.5, YAPC Chicago 2006
  • 2. for the purposes of this tutorial Perl 5 never existed
  • 3. Don’t really do this $ ln -s /usr/local/bin/pugs /usr/bin/perl
  • 4. Allison, Audrey, Damian, and Larry... The Apple Store on Michigan Avenue is giving away free MacBooks for the next 90 minutes take the Red Line up to Chicago then walk towards the lake
  • 5. Introduction It’s a completely new language That other one never existed Llama 6 is a long way off This is the basics of the language Next week it might be different
  • 6. Basis for this talk Apocalypses Exegeses Synopses Perl6-Pugs-N-NN docs/quickref/data examples/ Actual Pugs behavior
  • 8. We’re liars There’s not enough time for everything We can’t tell you the whole story There are other ways to do things Damian gave you the Perl 6 update just now We wrote these slides last week
  • 9. In 80 minutes, we can cover Data Variables Control structures Input / Output
  • 10. If we had more time Subroutines Regular expressions Using modules Creating classes, objects, &c.
  • 11. Q & A at the end just find Damian in the hallway
  • 12. Try this at home not at work
  • 13. Getting Pugs http://www.pugscode.org Needs Glasgow Haskell Compiler (GHC) Get the binary builds compilation can take a long, long time and it eats up your CPU
  • 14. Making a P6 program Programs are just text files Syntax is C like, mostly whitespace is not significant, mostly statements separated by semicolons comments are # to end of line Use pugs on the shebang line #!/usr/local/bin/pugs say quot;Hello Worldquot;;
  • 15. Objects & Methods Data are objects or nouns Methods are verbs (actions) Object.Method #!/usr/local/bin/pugs quot;Hello Worldquot;.say;
  • 16. Run from command line $ pugs hello.p6 Hello World $ ./hello.p6 Hello World $ pugs -e 'say quot;Hello Worldquot;' Hello World $ pugs pugs> say quot;Hello Worldquot; Hello World bool::true
  • 18. Scalars are single values Numbers Strings Boolean
  • 19. Literal numbers 3 3.14 3.14e7 -4.56 0 123_456 0b0110 0o377 0o644 0xAB 0xDEAD_BEEF
  • 20. say say can be used a method Outputs the value and tacks on a newline More output stuff later quot;Hello Worldquot;.say; say quot;Hello Worldquot;;
  • 21. Arithmetic 2 + 3 5 2 - 3 -1 2 * 3 6 2 / 3 0.66666666... 2 ** 3 8 2 % 3 2
  • 22. Method call forms # indirect form say 3; # direct form 3.say; # parens to group ( 10 / 3 ).say; # / really just a method (10./(3)).say;
  • 23. Strings Sequence of zero or more characters Perl inter-converts automatically with numbers
  • 24. Single quoted strings 'Hello World'.say; 'I said 'Hello World!''.say; 'I need a literal '.say; q/I don't need to escape/.say;
  • 25. Double quoted strings quot;HellotWorldquot;.say; quot;I said quot;Hello World!quot;quot;.say; quot;Hello Worldquot;.print; # no newline quot;Hello Worldnquot;.print; qq/Hello Worldn/.print;
  • 26. String concatenation ~ stitches strings together ( quot;Helloquot; ~ quot;Worldquot; ).say; HelloWorld ( quot;Helloquot; ~ quot; quot; ~ quot;Worldquot; ).say; Hello World
  • 27. String replication x repeats and joins string ( quot;Hiquot; x 3 ).say; HiHiHi ( quot;Hiquot; x 2.5 ).say; floor - HiHi ( quot;Hiquot; x -1 ).say; error!
  • 28. Booleans True or False, Yes or No, On or Off, 1 or nothing Often the result of a comparison
  • 29. Numeric comparisons 5 < 6 True 5 > 6 False 5 == 6 False 5 <= 6 True 5 >= 6 False 5 != 6 True
  • 30. String comparisons 'fred' lt 'barney' False 'fred' gt 'barney' True 'fred' eq 'barney' False 'fred' le 'barney' False 'fred' ge 'barney' True 'fred' ne 'barney' True
  • 31. Scalar variables Stores a single value Name starts with a letter or underscore, followed by letters, underscores, or digits Has a special symbol (sigil) prepended, $ Starts off undefined (absence of value) We have to assign it a value Declare with my on first use
  • 32. Scalar Assignment my $num = 5; quot;The number is $numquot;.say; my $str = quot;Pugsquot;; quot;Just another $str hacker, quot;.say;
  • 33. Scalar value type The ref method gives the type of scalar my $s1 = 5 < 6; my $s2 = quot;Perlquot;; my $s3 = 6 - 5; my $s4 = 3.14; $s1.ref.say; Bool $s2.ref.say; Str $s3.ref.say; Int $s4.ref.say; Rat
  • 34. Standard input quot;Enter a name> quot;.print; my $input = (=$*IN).chomp; quot;Enter another name> quot;.print; $input = (=<>).chomp;
  • 36. if-elsif-else if 5 < 6 { quot;5 less than 6quot;.say } if 5 > 6 { quot;5 more than 6quot;.say } else { quot;5 not more than 6quot;.say } if 5 < 4 { quot;5 less than 4quot;.say } elsif 5 > 4 { quot;5 more than 4quot;.say } else { quot;5 not more than 4quot;.say }
  • 37. Complex comparisons if( 5 < $x < 10 ) { quot;$x is between 5 and 10quot;.say } else { quot;$x is not between 5 and 10quot;.say }
  • 38. Junctions my $num = 5; if( $num == any( <5 6 7> ) ) { quot;$num is in the setquot;.say } else { quot;$num is not in the setquot;.say }
  • 39. Expression modifiers Apply a condition to a single expression quot;5 is greaterquot;.say if 5 > 6; quot;5 is lessquot;.say if 5 < 6;
  • 40. loop loop ( init; test; increment ){ } loop ( $i = 1; $i < 10; $i++ ) { quot;I can count to $iquot;.say; } I can count to 1 I can count to 2 I can count to 3 I can count to 4 ...
  • 41. next skips the rest of the block goes to next iteration loop ( $i = 1; $i < 10; $i++ ) { next if $i % 2; quot;I can count to $iquot;.say; } I can count to 2 I can count to 4 I can count to 6 I can count to 8
  • 42. last skips the rest of the iterations continues after the loop loop ( $i = 1; $i < 10; $i++ ) { last if $i == 5; quot;I can count to $iquot;.say; } I can count to 2 I can count to 4 I can count to 6 I can count to 8
  • 43. redo starts the current iteration again uses the same element (if any) loop { quot;Do you like pugs?> quot;.print; my $answer = (=$*IN).chomp; redo if $answer ne 'yes'; last; }
  • 44. Number guesser quot;Guess secret number from 1 to 10quot;.say; my $secret = rand(10+1).int; loop { quot;Enter your guess> quot;.print; my $guess = (=$*IN).chomp; if $guess < $secret { quot;Too low!quot;.say; redo } elsif $guess > $secret { quot;Too high!quot;.say; redo } else { quot;That's it!quot;.say; last } }
  • 46. Literal Lists ( 1, 2, 3, 4 ) <a b c d> my $x = 'baz' <<foo bar $x>> «foo bar $x» ( 1 .. 3 ) ( 'a' .. 'z' )
  • 47. List replication 'f' xx 4 <f f f f> <g> xx 6 <g g g g g g> < a b c > xx 2 < a b c a b c >
  • 48. Joining elements <1 2 3 4>.join(' ') 1 2 3 4 <1 3 5 7>.join(':') 1:3:5:7
  • 49. Ranges ( 4 .. 7 ) < 4 5 6 7 > ( 'a' .. 'e' ) < a b c d e > reverse 1 .. 3 < 3 2 1 > ( 1 .. 3 ).reverse < 3 2 1 >
  • 50. Arrays Array variables store multiple scalars Indexes list with integers, starting at 0 Same variable naming rules as a scalar Special character is @ (think @rray) Name comes from a separate namespace Nothing to do with scalar of same name
  • 51. Array assignment my @a = < a b c >; my @a = << a b $c >> my @a = 1 .. 6;
  • 52. Bounds my @r = 37..42; say quot;Minimum is quot; ~ @r.min; say quot;Maximum is quot; ~ @r.max; my @a = < 3 5 9 2 5 0 1 8 4 >; say quot;Minimum is quot; ~ @a.min; say quot;Maximum is quot; ~ @a.max;
  • 53. Array elements my @a = <a b c d e f g>; my $first = @a[0]; a my $last = @a[-1]; g my $count = @a.elems; 7 my @slice = @a[0,-1]; < a g >
  • 54. Unique elements my @a = <a b c a b d b d>; my @b = @a.uniq; < a b c d >
  • 55. Hyperoperators Apply operator pair wise my @nums = 1 .. 10; my @alphas = 'a' .. 'j'; my @stitch = @nums >>~<< @alphas; < 1a 2b 3c 4d 5e 6f 7g 8h 9i 10j > my @square = @nums >>*<< @nums; < 1 4 9 16 25 36 49 64 81 100 >
  • 56. for for 1 .. 5 -> $elem { quot;I saw $elemquot;.say; } I saw 1 I saw 2 I saw 3 I saw 4 I saw 5
  • 57. for for @ARGS -> $arg { quot;I saw $arg on the command linequot;.say; } I saw fred on the command line I saw barney on the command line I saw betty on the command line
  • 59. Hash variables Hash variables stores unordered pairs Index is the “key”, a unique string Makes a map from one thing to another Same naming rules as scalar and array Special character is % (think %hash) Name comes from a separate namespace Nothing to do with scalar, array of same name
  • 60. Hash elements my %h = <a 5 b 7 c 3>; my $a_value = %h{'a'}; 5 my $b_value = %h<b>; 7 my $count = %h.elems; 3 my @values = %h{ <b c> }; < 7 3 > my @values = %h<b c>; < 7 3 >
  • 61. my %hash = ( 'fred' => 'flintstone', 'barney' => 'rubble', ); %hash.say; barney rubblefred flintstone %hash.join(quot;nquot;).say; barney rubble fred flintstone
  • 62. Hash keys my %hash = ( 'fred' => 'flintstone', 'barney' => 'rubble', ); for %hash.keys -> $key { quot;$key: %hash{$key}quot;.say; } barney: rubble fred: flintstone
  • 63. Hash values my %hash = ( 'fred' => 'flintstone', 'barney' => 'rubble', ); for %hash.values -> $value { quot;One value is $valuequot;.say; } One value is rubble One value is flintstone
  • 64. By pairs my %hash = ( 'fred' => 'flintstone', 'barney' => 'rubble', ); for %hash.kv -> $key, $value { quot;$key ---> $valuequot;.say; } barney ---> rubble fred ---> flintstone
  • 65. Counting words my %words; for =<> -> $line { for $line.chomp.split -> $word { %words{$word}++; } } for %words.kv -> $k, $v { quot;$k: $vquot;.say }
  • 66. exists True if the key is in the hash Does not create the key my @chars = <fred wilma barney betty>; my %hash = ( 'fred' => 'flintstone', 'barney' => 'rubble', ); for @chars -> $char { quot;$char existsquot;.say if %hash.exists($char); }
  • 67. delete Removes pair from hash my %hash = ( 'fred' => 'flintstone', 'barney' => 'rubble', 'dino' => undef, ); %hash.delete('dino'); %hash.join(quot;nquot;).say; barney rubble fred flintstone
  • 69. Standard input quot;Enter a name> quot;.print; my $input = (=$*IN).chomp; quot;Enter another name> quot;.print; $input = (=<>).chomp;
  • 70. File input operator The =<> reads from files from the command line arguments for =<> -> $line { quot;Got $linequot;.print; }
  • 71. Opening files to read my $fh = open( $file, :r ); for =$fh -> $line { quot;Got $linequot;.print; }
  • 72. Die-ing my $file = quot;not_therequot;; my $fh = open( quot;not_therequot;, :r ) err die quot;Couldn’t open $file: $!quot;; for =$fh -> $line { quot;Got $linequot;.print; }
  • 73. try Catches exceptions try { die quot;I'm dyingquot; if time.int % 2; quot;I made itquot;.say; }; quot;Error was $!quot;.say if $!;
  • 74. Standard filehandles Default filehandles $*OUT and $*ERR $*ERR.say( quot;This goes to stderrquot; ); $*OUT.say( quot;This goes to stdoutquot; );
  • 75. Writing to files my $file = quot;not_therequot;; my $fh = open( quot;not_therequot;, :w ) err die quot;Couldn’t open $file: $!quot;; print $fh: @stuff; # $fh.print( @stuff );
  • 76. try Catches exceptions try { die quot;I'm dyingquot; if time.int % 2; quot;I made itquot;.say; }; quot;Error was $!quot;.say if $!;
  • 78. File tests As with test(1) my $file = quot;file_tests.p6quot;; quot;Found filequot;.say if -e $file; quot;Found readable filequot;.say if -r $file; my $file_size = -s $file; quot;File size is $file_sizequot;.say;
  • 80. given is like C’s switch (but better) variable value types complex data structures regular expressions - PCRE and new stuff sorting, string manipulation etc. subroutines have better calling conventions
  • 81. Summary Perl 6 is a new language It borrows from Perl (and ancestors) It’s not done yet, but it’s almost usable