Новое в Perl 5.10

593 views
521 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
593
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Новое в Perl 5.10

  1. 1. Perl 5.10
  2. 2. CPAN perl-5.10.0-RC1
  3. 3. #!/perl5.10/bin/perl >
perl5.10
script.pl
  4. 4. use
feature
  5. 5. use
feature
qw( 



say 



switch 



state );
  6. 6. use
feature
qw( 



say 



switch 



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



say 



switch 



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



say 



switch 



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

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

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










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










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










4
  17. 17. my
$_;
  18. 18. for
(1..5)
{ 



my
$_
=
'*'; 



print; }














*****
  19. 19. $::_
  20. 20. for
(1..5)
{ 



my
$_
=
'*'; 



print
$::_; }














12345
  21. 21. our
$_;
  22. 22. for
(1..5)
{ 



our
$_
=
'*'; 



print
$::_; }














*****
  23. 23. >
perl5.10
‐E
 

quot;say
for
1..3quot; >
perl6
‐e
 

quot;say
for
1..3quot;
  24. 24. >
perl5.10
‐E
 1 

quot;say
for
1..3quot; 2 3 n >
perl6
‐e
 n 

quot;say
for
1..3quot; n
  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. ~~
  29. 29. use
feature
'say'; my
$date
 



=
'Thu
22
November,
2007'; say
'Today'
if
$date
~~
/Thu/;
  30. 30. use
feature
'switch';
  31. 31. use
feature
qw(switch
say); my
$tag
=
'perlrus08'; given
($tag)
{ 



when
('perlrus08')
{ 







say
'Yes'; 



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



when
('perlrus08')
{ 







say
'Yes'; 



} 



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



when
(/d+/)
{ 







say
'digits'; 







continue; 



} 



when
(/perl/i)
{ 







say
'Perl'; 



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



state
$value
=
0; 



$value++; 



say
$value; } counter();












1 counter();












2 counter();












3
  40. 40. Регулярные выражения
  41. 41. Именованные
буферы my
$date
=
'Thu
22
November
2007'; $date
=~
/ 



(










w+

)



s+ 



(










d+

)



s+ 



(










w+

)



s+ 



(










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


















Thu say
$4;


















2007
  42. 42. Именованные
буферы my
$date
=
'Thu
22
November
2007'; $date
=~
/ 



(?<wday>



w+

)



s+ 



(?<day>




d+

)



s+ 



(?<month>


w+

)



s+ 



(?<year>



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












Thu say
$+{year};












2007
  43. 43. Именованные
буферы my
$date
=
'Thu
22
November
2007'; $date
=~
s/ 






(?<year>d{4}) 



/ 







$+{year}
+
1 



/xe; say
$date;







Thu
22
November
2008
  44. 44. 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;
  45. 45. 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
  46. 46. my
$leap_years
=
'1992
1996
2004
2008'; $leap_years
=~
m/ 



( 







?<year>



1



d{3} 



) 


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










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



( 







?<year>



1



d{3}


s* 



)+ 


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










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



( 











( 















[^()]+ 











) 











 







| 











(?1) 



) 



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

quot; 



(?: 








[^quot;]++ 






| 








. 



)*+ 

quot; /x
  51. 51. (?|
...)
  52. 52. my
$re
=
qr/ 





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


| 





(w+),s*(d{4})) /x; '20071122'
=~
$re; say
quot;$1
.
$2
.
$3quot;; 'November,
2007'
=~
$re; say
quot;$4
.
$5quot;;
  53. 53. my
$re
=
qr/ 


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


| 





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





x0Dx0A? 


| 





[ 








x0A‐x0C 








x85 








x{2028} 








x{2029} 





] )
  62. 62. __END__ __DATA__ Андрей
Шитов
—
2007 andy@shitov.ru

|

http://shitov.ru

×