Perl 5.10

819 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
819
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Perl 5.10

  1. 1. Perl 5.10
  2. 2. Versions of Perl (perlhist) 5.000 17 October 1994 22 March 2000 5.6.0 18 July 2002 5.8.0 31 January 2006 5.8.8 18 December 2008 5.10
  3. 3. Versions of Perl (perlhist) 5.000 17 October 1994 22 March 2000 5.6.0 18 July 2002 5.8.0 31 January 2006 5.8.8 18 December 2008 5.10 ? 6.0
  4. 4. Versions of Perl (perlhist) 5.000 17 October 1994 22 March 2000 5.6.0 18 July 2002 5.8.0 31 January 2006 5.8.8 18 December 2008 5.10 Сhristmas 6.0
  5. 5. Versions of Perl (perlhist) 5.000 17 October 1994 22 March 2000 5.6.0 18 July 2002 5.8.0 31 January 2006 5.8.8 18 December 2008 5.10 2000 6.0
  6. 6. use
feature
  7. 7. use
feature
qw( 



say 



switch 



state );
  8. 8. use
feature
qw( 



say 



switch 



state ); use
feature
quot;:5.10quot;;
  9. 9. use
feature
qw( 



say 



switch 



state ); use
feature
quot;:5.10quot;; use
5.10.0;
  10. 10. use
feature
qw( 



say 



switch 



state ); use
feature
quot;:5.10quot;; use
v5.10.0;
  11. 11. #!/perl5.10/bin/perl use
feature
quot;***quot;;
  12. 12. #!/perl5.10/bin/perl use
feature
quot;sayquot;; say
quot;Perl
6?quot;;
  13. 13. #!/perl5.10/bin/perl use
feature
quot;sayquot;; say
quot;Perl
6?quot;; no
feature
quot;sayquot;;
  14. 14. >
perl5.10
‐e
 

quot;use
feature
qw(say);
say
$$;quot;
  15. 15. >
perl5.10
‐e
 

quot;use
feature
qw(say);
say
$$;quot; >
perl5.10
‐E
quot;say
$$;quot;
  16. 16. // defined‐or
  17. 17. my
$a; my
$b
=
$a
//
2; say
$b;










2
  18. 18. my
$c
=
0; my
$d
=
$c
//
3; say
$d;










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










4
  19. 19. my
$_;
  20. 20. for
(1..5)
{ 



my
$_
=
'*'; 



print; }














*****
  21. 21. $::_
  22. 22. for
(1..5)
{ 



my
$_
=
'*'; 



print
$::_; }














12345
  23. 23. our
$_;
  24. 24. for
(1..5)
{ 



our
$_
=
'*'; 



print
$::_; }














*****
  25. 25. use
strict
'refs'; my
$x
=
'***'; print
1
if
defined
$$x;
  26. 26. use
strict
'refs'; my
$var
=
'***'; print
defined
$$var 



?
'yes'
:
'no'; >
perl5.8.8
test.pl no

















  27. 27. use
strict
'refs'; my
$var
=
'***'; print
defined
$$var 



?
'yes'
:
'no'; >
perl5.10
test.pl Can't
use
string
(quot;xxxquot;)
as
a
 SCALAR
ref
while
quot;strict
refsquot;
 in
use
at
test.pl
line
3.






 

  28. 28. use
feature
'switch';
  29. 29. use
feature
qw(switch
say); my
$tag
=
'hrpw2008'; given
($tag)
{ 



when
('hrpw2008')
{ 







say
'Yes'; 



} }
  30. 30. use
feature
qw(switch
say); my
$tag
=
'hrpw2008'; given
($tag)
{ 



when
('hrpw2008')
{ 







say
'Yes'; 



} 



default
{say
'No';} }
  31. 31. when
(123) when
($value) when
(undef) when
([2001..2100]) when
(/d+/)
  32. 32. when
($_
>
0) when
(int) when
(int
$_) when
(&test_the_value) when
(test_the_value($_))
  33. 33. given
('hrpw2008')
{ 



when
(/d+/)
{ 







say
'digits'; 







continue; 



} 



when
(/perl/i)
{ 







say
'Perl'; 



} }
  34. 34. when
($what) == when
($_
~~
$what)
  35. 35. $left
~~
$right == $right
~~
$left
  36. 36. use
feature
'state';
  37. 37. sub
counter{ 



state
$value
=
0; 



$value++; 



say
$value; } counter();












1 counter();












2 counter();












3
  38. 38. Regular Expressions
  39. 39. Named saving parens my
$date
=
'Thu
15
April
2008'; $date
=~
/ 



(










w+

)



s+ 



(










d+

)



s+ 



(










w+

)



s+ 



(










d{4}) /x; say
$1;


















Thu say
$4;


















2008
  40. 40. Named saving parens my
$date
=
'Thu
15
April
2008'; $date
=~
/ 



(?<wday>



w+

)



s+ 



(?<day>




d+

)



s+ 



(?<month>


w+

)



s+ 



(?<year>



d{4}) /x; say
$+{wday};












Thu say
$+{year};












2008
  41. 41. Named saving parens my
$date
=
'Thu
15
April
2008'; $date
=~
s/ 






(?<year>d{4}) 



/ 







$+{year}
+
1 



/xe; say
$date;







Thu
15
April
2009
  42. 42. my
$code
=
'my
$value
=
100;
say
$value;'; $code
=~
s/ 



my

























s* 



(?<variable>



$[a‐z]+)


s* 



=


























s* 



(?<value>






[^;]+


)


s* 



;


























s* 



 



(?<other_code>.*?) 



 



(k<variable>) 



 



/$+{other_code}$+{value}/x; say
$code;


























say
100;
  43. 43. my
$leap_years
=
'1992
1996
2004
2008'; $leap_years
=~
m/ 



( 







?<year>



1



d{3} 



) 



s* 



( 







?<year>



2



d{3} 



) /x; say
$_
for
@{$‐{year}};










1996 

































2004
  44. 44. my
$leap_years
=
'1992
1996
2004
2008'; $leap_years
=~
m/ 



( 







?<year>



1



d{3} 



) 


 /gx; say
$_
for
@{$‐{year}};










1992
  45. 45. my
$leap_years
=
'1992
1996
2004
2008'; $leap_years
=~
m/ 



( 







?<year>



1



d{3}


s* 



)+ 


 /gx; say
$_
for
@{$‐{year}};










1996
  46. 46. use
feature
'say'; my
$expr
=
'1
+
(2
+
(3
+
(4
+
5)
+
6))'; $expr
=~
s/ 



( 











( 















[^()]+ 











) 











 







| 











(?1) 



) 



/say
$1;/xge;
  47. 47. Posessive quantifiers ?+ *+ ++ {min,
max}+
  48. 48. / 

quot; 



(?: 








[^quot;]++ 






| 








. 



)*+ 

quot; /x
  49. 49. (?|
...)
  50. 50. my
$re
=
qr/ 





(d{4})(dd)(dd) 


| 





(w+),s*(d{4})) /x; '20080415'
=~
$re; say
quot;$1
.
$2
.
$3quot;; 'April,
2008'
=~
$re; say
quot;$4
.
$5quot;;
  51. 51. my
$re
=
qr/ 


(?|(d{4})(dd)(dd) 


| 





(w+),s*(d{4}))) /x; '20080415'
=~
$re; say
quot;$1
.
$2
.
$3quot;; 'April,
2008'
=~
$re; say
quot;$1
.
$2quot;;
  52. 52. g{N} gN
  53. 53. g{‐N}
  54. 54. k<named> == g{named}
  55. 55. K
  56. 56. v h
  57. 57. V H
  58. 58. R
  59. 59. R (?> 





x0Dx0A? 


| 





[ 








x0A‐x0C 








x85 








x{2028} 








x{2029} 





] )
  60. 60. Smart matching ~~
  61. 61. $a
~~
$b == $b
~~
$a
  62. 62. my
$b; $b
~~
undef !defined
$b
  63. 63. my
$c
=
'abc'; $c
~~
'abc' $c
eq
'abc'
  64. 64. my
$c
=
'abc'; $c
~~
/b/ $c
=~
/b/
  65. 65. my
@a
=
(1..3); my
@b
=
(1..3); @a
~~
@b 1
==
1
&&
2
==
2
&&
3
==
3
  66. 66. my
@a
=
(1..3); my
@b
=
(1..3); my
@c
=
(3..5); @a
~~
@c 1
==
3
&&
2
==
4
&&
3
==
5
  67. 67. my
@d
=
(123,
'abc'); my
@e
=
(qr/d/,
qr/w/); @d
~~
@e 123
~~
/d/
&& 'abc'
~~
/w/
  68. 68. my
@f
=
('a'..'f'); @f
~~
'd' grep
{$_
eq
'd'}
@f
  69. 69. my
@g
=
(1..10); @g
~~
7 grep
{$_
==
7}
@g
  70. 70. my
@g
=
(1..10); @g
~~
7.0 grep
{$_
==
7.0}
@g
  71. 71. my
@g
=
(1..10); @g
~~
'7.0' grep
{$_
eq
'7.0'}
@g
  72. 72. my
@g
=
(1..10); @g
~~
/^d$/ grep
{$_
=~
/^d$/}
@g
  73. 73. 3.14
~~
'3.14' 3.14
==
'3.14'
  74. 74. 3.14
~~
'3.14%' 3.14
==
'3.14%'
  75. 75. sub
subA
{return
2} sub
subB
{return
2} subA
~~
subB subA()
==
subB()
  76. 76. sub
subA
{return
2} my
$subA1_ref
=
&subA; my
$subA2_ref
=
&subA; $subA1_ref
~~
$subA2_ref $subA1_ref
==
$subA2_ref
  77. 77. sub
subA
{return
2} my
$subA_ref
=
&subA; $a
~~
$subA_ref $subA_ref‐>($a)
  78. 78. sub
subA
{return
2} my
$subA_ref
=
&subA; ‐1
~~
$subA_ref $subA_ref‐>(‐1)
  79. 79. my
%h
=
(a
=>
'alpha', 








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








b
=>
'beta'); my
@f
=
('a'..'f'); %h
~~
@f grep
{$_}
@h{@f}
  81. 81. my
%h
=
(a
=>
'alpha', 








b
=>
'beta'); %h
~~
/[A‐F]/i grep
{/[A‐F]/i}
keys
%h
  82. 82. my
%h
=
(a
=>
'alpha', 








b
=>
'beta'); my
%hh
=
(b
=>
1,
a
=>
2); %h
~~
%hh [sort
keys
%h]
~~ [sort
keys
%hh]
  83. 83. Elements of Perl 6 in Perl 5.10
  84. 84. Elements of Perl 6 in Perl 5.10 and differencies
  85. 85. say
  86. 86. my
$x
=
'HRPW2008'; say
$x;
  87. 87. 5.10 my
$x
=
'HRPW2008'; say
$x; HRPW2008
  88. 88. 6 my
$x
=
'HRPW2008'; say
$x; HRPW2008
  89. 89. 5.10 my
$x
=
'HRPW2008'; say
($x);
  90. 90. 5.10 my
$x
=
'HRPW2008'; say
($x); HRPW2008
  91. 91. 6 my
$x
=
'HRPW2008'; say
($x); HRPW2008
  92. 92. 6 my
$x
=
'HRPW2008'; say($x); HRPW2008
  93. 93. 6 my
$x
=
'HRPW2008; $x.say; HRPW2008
  94. 94. 5.10 my
$x
=
'HRPW2008'; $x.say;
  95. 95. 5.10 my
$x
=
'HRPW2008'; $x.say; String concatenation!
  96. 96. 6 my
$x
=
'HRPW2008'; $x.say(); HRPW2008
  97. 97. $_
  98. 98. for
(1..3)
{ 



say; }
  99. 99. 5.10 for
(1..3)
{ 



say; } 1 2 3
  100. 100. 6 for
(1..3)
{ 



say; } n n n
  101. 101. 6 for
(1..3)
{ 



say
$_; } 1 2 3
  102. 102. 6 for
(1..3)
{ 



$_.say; } 1 2 3
  103. 103. 6 for
(1..3)
{ 



.say; } 1 2 3
  104. 104. switch
  105. 105. 5.10, 6 my
$str
=
quot;YAPC::Asiaquot;;
 given
($str)
{ 



when
(/Asia/)
{ 







say
quot;Asiaquot; 



} }
  106. 106. 5.10, 6 my
$str
=
quot;YAPC::Asiaquot;;
 given
($str)
{ 



when
(/Asia/)
{ 







say
quot;Asiaquot; 



} }
  107. 107. 6 my
$str
=
quot;YAPC::Asiaquot;;
 given
($str)
{ 



when
(/Asia/)
{ 







say
quot;Asiaquot; 



} }
  108. 108. 6 my
$str
=
quot;YAPC::Asiaquot;;
 given
$str
{ 



when
/Asia/
{ 







say
quot;Asiaquot; 



} }
  109. 109. 6 my
$str
=
quot;YAPC::Asiaquot;;
 given
$str
{ 



say
quot;Asiaquot;
when
/Asia/
 }
  110. 110. state
  111. 111. sub
f
{ 


state
$c; 


say
++$c; }
  112. 112. sub
f
{ 


state
$c; 


say
++$c; } f();
f();
f();
  113. 113. 5.10 sub
f
{ 


state
$c; 


say
++$c; } f();
f();
f(); 1
2
3
  114. 114. 6 sub
f
{ 


state
$c; 


say
++$c; } f();
f();
f(); 1
2
3
  115. 115. sub
f
{ 


state
$c
=
0; 


say
++$c; } f();
f();
f();
  116. 116. 5.10 sub
f
{ 


state
$c
=
0; 


say
++$c; } f();
f();
f(); 1
2
3
  117. 117. pugs sub
f
{ 


state
$c
=
0; 


say
++$c; } f();
f();
f(); 1
1
1
  118. 118. Croatian Perl Workshop, Zagreb, 2008 __END__ Andrew Shitov mail@andy.sh | http://andy.sh

×