Successfully reported this slideshow.
Your SlideShare is downloading. ×

The Joy of Smartmatch

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Perl6 in-production
Perl6 in-production
Loading in …3
×

Check these out next

1 of 23 Ad
Advertisement

More Related Content

Slideshows for you (20)

Advertisement

More from Andrew Shitov (20)

Recently uploaded (20)

Advertisement

The Joy of Smartmatch

  1. 1. The Joy of Smart Match
  2. 2. The Joy of Smartmatch
  3. 3. The Joy of ~~
  4. 4. Introduced in Perl 5.10
  5. 5. Introduced in 2007
  6. 6. How it was initially designed
  7. 7. How it is proposed to be
  8. 8. How it looks like now no  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) } Someone's 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.ru May 2013

×