23
The Joy of Smart Match

The Joy of Smartmatch

  • Upload
    andysh

  • View
    596

  • Download
    2

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: The Joy of Smartmatch

The Joyof Smart Match

Page 2: The Joy of Smartmatch

The Joyof Smartmatch

Page 3: The Joy of Smartmatch

The Joyof ~~

Page 4: The Joy of Smartmatch

Introduced in Perl 5.10

Page 5: The Joy of Smartmatch

Introduced in 2007

Page 6: The Joy of Smartmatch
Page 7: The Joy of Smartmatch

How it was initially designed

Page 8: The Joy of Smartmatch

How it is proposed to be

Page 9: The Joy of Smartmatch

How it looks like now

no  if  $]  >=  5.018,  "experimental::smartmatch";

Page 10: The Joy of Smartmatch
Page 11: The Joy of Smartmatch

How I use it

Page 12: The Joy of Smartmatch

help()  if  '-­‐-­‐help'  ~~  @ARGV;

Quick command line argument test

Page 13: The Joy of Smartmatch

someth()  if  $value  ~~  @arr;

Quick array element existance test

Page 14: The Joy of Smartmatch

someth()if  grep  {$_  ==  $value}  @arr;

Better than

Page 15: The Joy of Smartmatch

someth()if  grep  {$_  eq  $value}  @arr;

Better than

Page 16: The Joy of Smartmatch

someth()if  grep  {$value  =~  $_}  @arr;

Better than

Page 17: The Joy of Smartmatch

if  ($remote_addr  ~~          ['12.45.67.99',          '59.44.11.33'])  {...}

Quick IP address test

Page 18: The Joy of Smartmatch

if  ([$loaded_user,  $editable_user]  ~~        [            [  'OWNER',                      'ADMIN'],            [['ADMIN',  'OWNER'],  'USER'  ]                ])  {        $loaded_user-­‐>create($editable_user)}

Someone's similar usage

Page 19: The Joy of Smartmatch

sub  route  {        '/'}

URL match test

$page-­‐>render  if  $url  ~~  $page-­‐>route;

Page 20: The Joy of Smartmatch

sub  route  {        qr{^/admin/}}

URL match test

$page-­‐>render  if  $url  ~~  $page-­‐>route;

Page 21: The Joy of Smartmatch

~~is very Perlish

Page 22: The Joy of Smartmatch

Save the ~~

Page 23: The Joy of Smartmatch

__END__

Andrew Shitov [email protected]

May 2013