Upload
andysh
View
500
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
Life with Perl
Life with Perlboth 5 and 6
Life with Perlboth 5 and 6
5 stands for both 5.8.8 and 5.10
Versions of Perl (perlhist)
Lyrical digression
Time measuring
5.000 17 October 1994
5.6.0 22 March 2000
5.8.0 18 July 20025.8.8 31 January 2006
5.10 18 December 2008
Versions of Perl (perlhist)
5.000 17 October 1994
5.6.0 22 March 2000
5.8.0 18 July 20025.8.8 31 January 2006
5.10 18 December 2008
6.0 ?
Versions of Perl (perlhist)
5.000 17 October 1994
5.6.0 22 March 2000
5.8.0 18 July 20025.8.8 31 January 2006
5.10 18 December 2008
6.0 Сhristmas
Versions of Perl (perlhist)
5.000 17 October 1994
5.6.0 22 March 2000
5.8.0 18 July 20025.8.8 31 January 2006
5.10 18 December 2008
6.0 2000
Versions of Perl (perlhist)
Perl 6 docs, specs, thoughts
RFCsApocalypsesExegesesSynopses
5 != 6
Lyrical digression
Perl 5 mess
Perl 6 clean-up
5 != 64 != 5
Programme (script?)
Compiler
Virtual machine (VM)
Byte-code
Programme (script?)
Compiler
Virtual machine (VM)
Byte-code
BasicForthJakoLispm4OokPerl 6Perl 5PythonRubySchemeTcl
PASM
IMC
PBC
PIR
PIL
C#J#VB.NETJScript.NETmanaged C++
Ada (A#)F#COBOL.NETFORTRAN.NETPerl.NET
CLR
Java
JRE
Most practical compilers
languages/perl6 in parrot.tar.gz
Perl6::* on CPAN
PUGS
Rakudo
Most practical compilers
Rakudo
= = parrot/langauges/perl6
Most practical compilers
Rakudo
= = parrot/langauges/perl6 + years
PUGS. Made with Haskell
PUGS. Made with Haskell
Most full coverage of Perl 6 specs
PUGS. Made with Haskell
Most full coverage of Perl 6 specs
Needs latest version of GHC
It is not lyrics
PUGS. Made with Haskell
Most full coverage of Perl 6 specs
Needs latest version of GHC
Slow
PUGS. Made with Haskell
Most full coverage of Perl 6 specs
Needs latest version of GHC
Slow
Contains tests
Perl 6
perl.it
perl.it!
UTF-8
say and print
say"俄罗斯新闻网";
say and print
say"俄罗斯新闻网";
"俄罗斯新闻网".say;
say and print
say"俄罗斯新闻网";
"俄罗斯新闻网".say;
"俄罗斯新闻网".say();
say and print
say"string";
say123;
say(12+45);
say and print
say"string";
say123;
say(12+45);
"string".say;
123.say;
say and print
say"string";
say123;
say(12+45);
"string".say;
123.say;
3.14.say;
String length
my$str="俄罗斯新闻网";
say$str.length;
String length
my$str="俄罗斯新闻网";
say$str.length;
say$str.chars;6say$str.bytes;18
String concatenation
my$string_a="abcde";
my$string_b="fghij";
print$string_a.$string_b;5
print$string_a~$string_b;6
Lyrical digression
Different wishes
Different wishes
Variables
my$string="abcde";
my@array=(10,20,30);
my%hash=("one"=>10,"two"=>20);
Variables
my$string="abcde";
my@array=(10,20,30);
my%hash=("one"=>10,"two"=>20);
print$string;
print$string;
5
6
Variables
my$string="abcde";
my@array=(10,20,30);
my%hash=("one"=>10,"two"=>20);
5
6
print$array[1];
print@array[1];
Variables
my$string="abcde";
my@array=(10,20,30);
my%hash=("one"=>10,"two"=>20);
5
6
print$hash{"one"};
print%hash{"one"};
Variables
my$string="abcde";
my@array=(10,20,30);
my%hash=("one"=>10,"two"=>20);
5
6
print$hash{"one"};
print%hash{"one"};print%hash<one>;
print%hash<onetwo>;
Contexts
my@array=(5..10);
Contexts
my@array=(5..10);
say~@array; 5 6 7 8 9 10
Contexts
my@array=(5..10);
say~@array; 5 6 7 8 9 10
say+@array;6
Contexts
my@array=(5..10);
say~@array; 5 6 7 8 9 10
sayint@array;6
Contexts
my@array=(5..10);
say~@array; 5 6 7 8 9 10
sayint@array;6
say~hash@array;5678910
Contexts
my$value=100;
say$value;100
Contexts
my$value=100;
say$value;100
say?$value;1
Subroutines
subcallme($first,$second){say"$first,$second";}
callme(10,20);
Subroutines
subcallme($first,$second){say"$first,$second";}
callme(10,20);callme10,20;
Subroutines
subcallme($first,$second){say"$first,$second";}
callme(10,20);callme10,20;callme(10,20);
Subroutines
subcallme($first,$second){say"$first,$second";}
callme(10,20);callme10,20;callme(10,20);callme(second=>20,first=>10);
Subroutines
subcallme(@a,@b){say@a~","~@b;}
my@odd=(1,3);my@even=(2,4);callme@odd,@even;13,24
Subroutinessubcallme($argisrw)
subinc($value,$step=1)
Anonymous subroutines
my$print_line_break={print"<br/>";}
$print_line_break();
Anonymous subroutines
my$square=‐>($value){$value**2;}
say$square(20);400
Anonymous subroutines
my$square=‐>($value){$value**2;}
say$square(20);400say$square20;
Cycles
for@list{say$_;}
Cycles
for@list‐>$value{say$value;}
Cycles
for@list‐>$value{say$value;}
for@list,sub($value){say$value;}
Hyperoperators
my@odd=(1,3,5);my@even=(2,4,6);
my@sum=@odd»+«@even;say~@sum;3711
Hyperoperators
my@odd=(1,3,5);my@even=(2,4,6);
my@sum=@odd»+«@even;say~@sum;
my@next=@sum»+«1;say~@next;
Hyperoperators
my@odd=(1,3,5);my@even=(2,4,6);
my@sum=@odd>>+<<@even;say~@sum;
my@next=@sum>>+<<1;say~@next;
Hyperoperator monument
Junctions
say"yes"if20==10|20|30;
say"yes"if20==any(10,20,30);
Junctions
say"yes"if20==10|20|30;
say"yes"if20==any(10,20,30);
say"no"if21==none(10,20,30);
multi functions
multisubthe_name($scalar){...}multisubthe_name($s1,$s2){...}multisubthe_name(@array){...}
multi functions
multisubthe_name($scalar){...}multisubthe_name($s1,$s2){...}multisubthe_name(@array){...}
the_name($some_value);the_name($value1,$value2);the_name(@some_array);
Overriding operators
multiinfix:<+>($a,$b){return$a‐$b;}
say10+20;‐10
Overriding operators
multipostfix:<@>($power){return2**$power;}
say8@;256
Overriding operators
subpostfix:<power_of_two>($power){return2**$power;}
say8power_of_two;256
switch and case
given($x){when"a"{say...}when"b"{say...}when/<[a‐z]>/{...}default{...}}
Smart matching
~~
Smart matching
$a~~$b==
$b~~$a
Smart matching
my$b;
$b~~undef
!defined$b
Smart matching
my$c='abc';
$c~~'abc'
$ceq'abc'
Smart matching
my@a=(1..3);my@b=(1..3);
@a~~@b
1==1&&2==2&&3==3
Smart matching
my@f=('a'..'f');
@f~~'d'
grep{$_eq'd'}@f
Smart matching
my%h=(a=>'alpha',b=>'beta');
%h~~'a'
exists$h{'a'}
Smart matchingmy%h=(a=>'alpha',b=>'beta');my%hh=(b=>1,a=>2);
%h~~%hh[sortkeys%h]~~[sortkeys%hh]
Smart matching
Works
in Perl 5.10!
People think of Perl 6
I think of today's Perl 6
Classes
classAlphabet{}
my$abc=newAlphabet;
Classes
classAlphabet{has$.Name;has$Length;}
my$abc=newAlphabet;$abc.Name="Latin";$abc.Length=26;
Classes
classAlphabet{...methodinfo{say"$.Name;$Length";}}
$abc.info();
Classes
classAlphabet{methodBUILD{...}methodDESTROY{...}}
Inheritance
classCharactersisAlphabet{}
my$chars=newCharacters;$chars.info();
Inheritance
classCharactersisAlphabetisUniqueisNonLatin{}
Roles (interfaces?)
roleHaveName{has$Name;methodGetName{return$.Name;}}
classNamedAbcdoesHaveName{}
June 2003
June 2004
June 2004 2005
2005
2007?
2008?
Cancelled
Perl 6in
Perl 5.10
usefeatureqw(sayswitchstate);
subf{state$c;say++$c;}f();f();f();
123
//
defined-or
my$c=0;my$d=$c//3;say$d;0
my$e=0;my$f=$e||4;say$f;4
The Way Of The Camel
Rakudа-do
Rakudo
cdlanguages/perl6/makeperl6
Binding
my$hour=14;my$summertime:=$hour;
say$hour;$summertime++;
say$hour;
.WHATclassLanguage{has$!Name;
methodgive_name($newname){$!Name=$newname;}
methodsay_name{say"Thisis$!Name";}}
my$lang=Language.new();$lang.give_name('Perl6');$lang.say_name();
.WHATclassLanguage{}
my$lang=Language.new();
say$lang.WHAT;
sayLanguage.WHAT;
say'before';try{die'Bye!';}say'after';
try
regexlanguage{Perl|XML};
say"ok"
if'Perl'~~/<language>/;
say"notok"
unless'PHP'~~/<language>/;
Regexes
More
classFoo{};
myFoo$x;
$x=Foo.new();
More
async{
my@sum=@odd>>+<<@even;
}
More
atomic{
$a‐=100;
$b+=100;
}