The Joyof Smart Match
The Joyof Smartmatch
The Joyof ~~
Introducedin Perl 5.10
Introducedin 2007
How it was initially designed
How it is proposed to be
How it looks like nowno	  if	  $]	  >=	  5.018,	  "experimental::smartmatch";
How I use it
help()	  if	  -­‐-­‐help	  ~~	  @ARGV;Quick command line argument test
someth()	  if	  $value	  ~~	  @arr;Quick array element existance test
someth()if	  grep	  {$_	  ==	  $value}	  @arr;Better than
someth()if	  grep	  {$_	  eq	  $value}	  @arr;Better than
someth()if	  grep	  {$value	  =~	  $_}	  @arr;Better than
if	  ($remote_addr	  ~~	  	  	  	  	  [12.45.67.99,	  	  	  	  	  59.44.11.33])	  {...}Quick IP address test
if	  ([$loaded_user,	  $editable_user]	  ~~	  	  	  	  [	  	  	  	  	  	  [	  OWNER,	  	  	  	  	  	  	  	  	  	  	  ADMIN...
sub	  route	  {	  	  	  	  /}URL match test$page-­‐>render	  if	  $url	  ~~	  $page-­‐>route;
sub	  route	  {	  	  	  	  qr{^/admin/}}URL match test$page-­‐>render	  if	  $url	  ~~	  $page-­‐>route;
~~is very Perlish
Save the ~~
__END__Andrew Shitov andy@shitov.ruMay 2013
The Joy of Smartmatch
The Joy of Smartmatch
Upcoming SlideShare
Loading in …5
×

The Joy of Smartmatch

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

No notes for slide

The Joy of Smartmatch

  1. 1. The Joyof Smart Match
  2. 2. The Joyof Smartmatch
  3. 3. The Joyof ~~
  4. 4. Introducedin Perl 5.10
  5. 5. Introducedin 2007
  6. 6. How it was initially designed
  7. 7. How it is proposed to be
  8. 8. How it looks like nowno  if  $]  >=  5.018,  "experimental::smartmatch";
  9. 9. How I use it
  10. 10. help()  if  -­‐-­‐help  ~~  @ARGV;Quick command line argument test
  11. 11. someth()  if  $value  ~~  @arr;Quick array element existance test
  12. 12. someth()if  grep  {$_  ==  $value}  @arr;Better than
  13. 13. someth()if  grep  {$_  eq  $value}  @arr;Better than
  14. 14. someth()if  grep  {$value  =~  $_}  @arr;Better than
  15. 15. if  ($remote_addr  ~~          [12.45.67.99,          59.44.11.33])  {...}Quick IP address test
  16. 16. if  ([$loaded_user,  $editable_user]  ~~        [            [  OWNER,                      ADMIN],            [[ADMIN,  OWNER],  USER  ]                ])  {        $loaded_user-­‐>create($editable_user)}Someones similar usage
  17. 17. sub  route  {        /}URL match test$page-­‐>render  if  $url  ~~  $page-­‐>route;
  18. 18. sub  route  {        qr{^/admin/}}URL match test$page-­‐>render  if  $url  ~~  $page-­‐>route;
  19. 19. ~~is very Perlish
  20. 20. Save the ~~
  21. 21. __END__Andrew Shitov andy@shitov.ruMay 2013

×