Life With Perl

338 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
338
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Life With Perl

  1. 1. Life with Perl
  2. 2. Life with Perl both 5 and 6
  3. 3. Life with Perl both 5 and 6 5 stands for both 5.8.8 and 5.10
  4. 4. Versions of Perl (perlhist)
  5. 5. Lyrical digression
  6. 6. Time measuring
  7. 7. 5.000 17 October 1994 5.6.0 22 March 2000 5.8.0 18 July 2002 5.8.8 31 January 2006 5.10 18 December 2008 Versions of Perl (perlhist)
  8. 8. 5.000 17 October 1994 5.6.0 22 March 2000 5.8.0 18 July 2002 5.8.8 31 January 2006 5.10 18 December 2008 6.0 ? Versions of Perl (perlhist)
  9. 9. 5.000 17 October 1994 5.6.0 22 March 2000 5.8.0 18 July 2002 5.8.8 31 January 2006 5.10 18 December 2008 6.0 Сhristmas Versions of Perl (perlhist)
  10. 10. 5.000 17 October 1994 5.6.0 22 March 2000 5.8.0 18 July 2002 5.8.8 31 January 2006 5.10 18 December 2008 6.0 2000 Versions of Perl (perlhist)
  11. 11. Perl 6 docs, specs, thoughts RFCs Apocalypses Exegeses Synopses
  12. 12. 5 != 6
  13. 13. Lyrical digression
  14. 14. Perl 5 mess
  15. 15. Perl 6 clean-up
  16. 16. 5 != 6 4 != 5
  17. 17. Programme (script?) Compiler Virtual machine (VM) Byte-code
  18. 18. Programme (script?) Compiler Virtual machine (VM) Byte-code
  19. 19. Basic Forth Jako Lisp m4 Ook Perl 6 Perl 5 Python Ruby Scheme Tcl PASM IMC PBC PIR PIL
  20. 20. C# J# VB.NET JScript.NET managed C++ Ada (A#) F# COBOL.NET FORTRAN.NET Perl.NET CLR
  21. 21. Java JRE
  22. 22. Most practical compilers languages/perl6 in parrot.tar.gz Perl6::* on CPAN PUGS Rakudo
  23. 23. Most practical compilers Rakudo = = parrot/langauges/perl6
  24. 24. Most practical compilers Rakudo = = parrot/langauges/perl6 + years
  25. 25. PUGS. Made with Haskell
  26. 26. PUGS. Made with Haskell Most full coverage of Perl 6 specs
  27. 27. PUGS. Made with Haskell Most full coverage of Perl 6 specs Needs latest version of GHC
  28. 28. It is not lyrics
  29. 29. PUGS. Made with Haskell Most full coverage of Perl 6 specs Needs latest version of GHC Slow
  30. 30. PUGS. Made with Haskell Most full coverage of Perl 6 specs Needs latest version of GHC Slow Contains tests
  31. 31. Perl 6
  32. 32. perl.it
  33. 33. perl.it!
  34. 34. UTF-8
  35. 35. say and print say
"俄罗斯新闻网";
  36. 36. say and print say
"俄罗斯新闻网"; "俄罗斯新闻网".say;
  37. 37. say and print say
"俄罗斯新闻网"; "俄罗斯新闻网".say; "俄罗斯新闻网".say();
  38. 38. say and print say
"string"; say
123; say(12
+
45);
  39. 39. say and print say
"string"; say
123; say(12
+
45); "string".say; 123.say;
  40. 40. say and print say
"string"; say
123; say(12
+
45); "string".say; 123.say; 3.14.say;
  41. 41. String length my
$str
=
"俄罗斯新闻网"; say
$str.length;
  42. 42. String length my
$str
=
"俄罗斯新闻网"; say
$str.length; say
$str.chars;



6 say
$str.bytes;



18
  43. 43. String concatenation my
$string_a
=
"abcde"; my
$string_b
=
"fghij"; print
$string_a
.
$string_b;5 print
$string_a
~
$string_b;6
  44. 44. Lyrical digression
  45. 45. Different wishes
  46. 46. Different wishes
  47. 47. Variables my
$string
=
"abcde"; my
@array
=
(10,
20,
30); my
%hash
=
("one"
=>
10, 











"two"
=>
20);
  48. 48. Variables my
$string
=
"abcde"; my
@array
=
(10,
20,
30); my
%hash
=
("one"
=>
10, 











"two"
=>
20); print
$string; print
$string; 5 6
  49. 49. Variables my
$string
=
"abcde"; my
@array
=
(10,
20,
30); my
%hash
=
("one"
=>
10, 











"two"
=>
20); 5 6 print
$array[1]; print
@array[1];
  50. 50. Variables my
$string
=
"abcde"; my
@array
=
(10,
20,
30); my
%hash
=
("one"
=>
10, 











"two"
=>
20); 5 6 print
$hash{"one"}; print
%hash{"one"};
  51. 51. 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<one
two>;
  52. 52. Contexts my
@array
=
(5..10);
  53. 53. Contexts my
@array
=
(5..10); say
~@array; 5 6 7 8 9 10
  54. 54. Contexts my
@array
=
(5..10); say
~@array; 5 6 7 8 9 10 say
+@array;






6
  55. 55. Contexts my
@array
=
(5..10); say
~@array; 5 6 7 8 9 10 say
int
@array;



6
  56. 56. Contexts my
@array
=
(5..10); say
~@array; 5 6 7 8 9 10 say
int
@array;



6 say
~
hash
@array;
5

6 


















7

8 


















9

10
  57. 57. Contexts my
$value
=
100; say
$value;






100
  58. 58. Contexts my
$value
=
100; say
$value;






100 say
?$value;





1
  59. 59. Subroutines sub
callme
($first,
$second) { 


say
"$first,
$second"; } callme(10,
20);
  60. 60. Subroutines sub
callme
($first,
$second) { 


say
"$first,
$second"; } callme(10,
20); callme
10,
20;
  61. 61. Subroutines sub
callme
($first,
$second) { 


say
"$first,
$second"; } callme(10,
20); callme
10,
20; callme
(10,
20);
  62. 62. Subroutines sub
callme
($first,
$second) { 


say
"$first,
$second"; } callme(10,
20); callme
10,
20; callme
(10,
20); callme(second
=>
20, 






first
=>
10);
  63. 63. Subroutines sub
callme
(@a,
@b) { 


say
@a
~
",
"
~
@b; } my
@odd
=
(1,
3); my
@even
=
(2,
4); callme
@odd,
@even;

1
3,
2
4
  64. 64. Subroutines sub
callme
($arg
is
rw) sub
inc
($value,
$step
=
1)
  65. 65. Anonymous subroutines my
$print_line_break
= { 


print
"<br
/>"; } $print_line_break();
  66. 66. Anonymous subroutines my
$square
=
‐>
($value) { 


$value
**
2; } say
$square(20);






400
  67. 67. Anonymous subroutines my
$square
=
‐>
($value) { 


$value
**
2; } say
$square(20);






400 say
$square
20;
  68. 68. Cycles for
@list { 


say
$_; }
  69. 69. Cycles for
@list
‐>
$value { 


say
$value; }
  70. 70. Cycles for
@list
‐>
$value { 


say
$value; } for
@list,
sub
($value) { 


say
$value; }
  71. 71. Hyperoperators my
@odd
=
(1,
3,
5); my
@even
=
(2,
4,
6); my
@sum
=
@odd
»+«
@even;
 say
~@sum;



3
7
11
  72. 72. Hyperoperators my
@odd
=
(1,
3,
5); my
@even
=
(2,
4,
6); my
@sum
=
@odd
»+«
@even; say
~@sum;

 my
@next
=
@sum
»+«
1; say
~@next;


  73. 73. Hyperoperators my
@odd
=
(1,
3,
5); my
@even
=
(2,
4,
6); my
@sum
=
@odd
>>+<<
@even; say
~@sum;

 my
@next
=
@sum
>>+<<
1; say
~@next;


  74. 74. Hyperoperator monument
  75. 75. Junctions say
"yes" if
20
==
10
|
20
|
30;
 say
"yes" if
20
==
any
(10,
20,
30);
  76. 76. Junctions say
"yes" if
20
==
10
|
20
|
30;
 say
"yes" if
20
==
any
(10,
20,
30); say
"no" if
21
==
none
(10,
20,
30);
  77. 77. multi functions multi
sub
the_name
($scalar)
{...} multi
sub
the_name
($s1,
$s2)
{...} multi
sub
the_name
(@array)
{...}
  78. 78. multi functions multi
sub
the_name
($scalar)
{...} multi
sub
the_name
($s1,
$s2)
{...} multi
sub
the_name
(@array)
{...} the_name($some_value); the_name($value1,
$value2); the_name(@some_array);
  79. 79. Overriding operators multi
infix:<+>
($a,
$b) { 


return
$a
‐
$b; } say
10
+
20;




‐10
  80. 80. Overriding operators multi
postfix:<@>
($power) { 


return
2
**
$power; } say
8@;

















256
  81. 81. Overriding operators sub
postfix:<power_of_two>
($power) { 


return
2
**
$power; } say
8
power_of_two;





256
  82. 82. switch and case given
($x) { 


when
"a"
{say
...} 


when
"b"
{say
...} 


when
/<[a‐z]>/
{...} 


default

{...} }
  83. 83. Smart matching ~~
  84. 84. Smart matching $a
~~
$b == $b
~~
$a
  85. 85. Smart matching my
$b; $b
~~
undef !defined
$b
  86. 86. Smart matching my
$c
=
'abc'; $c
~~
'abc' $c
eq
'abc'
  87. 87. Smart matching my
@a
=
(1..3); my
@b
=
(1..3); @a
~~
@b 1
==
1
&&
2
==
2
&&
3
==
3
  88. 88. Smart matching my
@f
=
('a'..'f'); @f
~~
'd' grep
{$_
eq
'd'}
@f
  89. 89. Smart matching my
%h
=
(a
=>
'alpha', 








b
=>
'beta'); %h
~~
'a' exists
$h{'a'}
  90. 90. Smart matching my
%h
=
(a
=>
'alpha', 








b
=>
'beta'); my
%hh
=
(b
=>
1,
a
=>
2); %h
~~
%hh [sort
keys
%h]
~~ [sort
keys
%hh]
  91. 91. Smart matching Works in Perl 5.10!
  92. 92. People think of Perl 6
  93. 93. I think of today's Perl 6
  94. 94. Classes class
Alphabet { } my
$abc
=
new
Alphabet;
  95. 95. Classes class
Alphabet { 


has
$.Name; 


has
$Length; } my
$abc
=
new
Alphabet; $abc.Name
=
"Latin"; $abc.Length
=
26;
  96. 96. Classes class
Alphabet { 


... 


method
info 


{ 





say
"$.Name;
$Length"; 


} } $abc.info();
  97. 97. Classes class
Alphabet { 


method
BUILD
{...} 


method
DESTROY
{...} }
  98. 98. Inheritance class
Characters
is
Alphabet { } my
$chars
=
new
Characters; $chars.info();
  99. 99. Inheritance class
Characters
 


is
Alphabet 


is
Unique 


is
NonLatin { }
  100. 100. Roles (interfaces?) role
HaveName { 


has
$Name; 


method
GetName 


{return
$.Name;} } class
NamedAbc
does
HaveName
{}
  101. 101. June 2003
  102. 102. June 2004
  103. 103. June 2004 2005
  104. 104. 2005
  105. 105. 2007?
  106. 106. 2008?
  107. 107. Cancelled
  108. 108. Perl 6 in Perl 5.10
  109. 109. use
feature
qw( 



say 



switch 



state );
  110. 110. sub
f
{ 


state
$c; 


say
++$c; } f();
f();
f(); 1
2
3
  111. 111. // defined-or
  112. 112. my
$c
=
0; my
$d
=
$c
//
3; say
$d;










0 my
$e
=
0; my
$f
=
$e
||
4; say
$f;










4
  113. 113. Perl 6 today is Rakudo www.rakudo.org
  114. 114. The Way Of The Camel Rakudа-do
  115. 115. Rakudo cd
languages/perl6/
 make
perl6
  116. 116. Binding my
$hour
=
14;
 my
$summertime
:=
$hour; say
$hour;
 $summertime++;
 say
$hour;
  117. 117. .WHAT class
Language
{
 



has
$!Name; 



method
give_name
($newname)
{
 







$!Name
=
$newname;
 



} 



method
say_name
{
 







say
"This
is
$!Name";
 



}
 } my
$lang
=
Language.new();
 $lang.give_name('Perl
6');
 $lang.say_name();
  118. 118. .WHAT class
Language
{
 } my
$lang
=
Language.new();
 say
$lang.WHAT; say
Language.WHAT;
  119. 119. say
'before';
 try
{
 


die
'Bye!';
 }
 say
'after'; try
  120. 120. regex
language
{Perl|XML}; say
"ok"
 



if
'Perl'
~~
/<language>/;
 say
"not
ok"
 



unless
'PHP'
~~
/<language>/; Regexes
  121. 121. More class
Foo{}; my
Foo
$x; $x
=
Foo.new();
  122. 122. More async
{ 



my
@sum
=
@odd
>>+<<
@even; }
  123. 123. More atomic
{ 



$a
‐=
100; 



$b
+=
100; }
  124. 124. __END__ Andrew Shitov mail@andy.sh | http://andy.sh DORS/CLUC, Zagreb, 2008

×