Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Joy of Smartmatch

973 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

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

×