The Joy of Smartmatch
-
Upload
andysh -
Category
Technology
-
view
591 -
download
2
description
Transcript of The Joy of Smartmatch
![Page 1: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/1.jpg)
The Joyof Smart Match
![Page 2: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/2.jpg)
The Joyof Smartmatch
![Page 3: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/3.jpg)
The Joyof ~~
![Page 4: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/4.jpg)
Introduced in Perl 5.10
![Page 5: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/5.jpg)
Introduced in 2007
![Page 6: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/6.jpg)
![Page 7: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/7.jpg)
How it was initially designed
![Page 8: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/8.jpg)
How it is proposed to be
![Page 9: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/9.jpg)
How it looks like now
no if $] >= 5.018, "experimental::smartmatch";
![Page 10: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/10.jpg)
![Page 11: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/11.jpg)
How I use it
![Page 12: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/12.jpg)
help() if '-‐-‐help' ~~ @ARGV;
Quick command line argument test
![Page 13: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/13.jpg)
someth() if $value ~~ @arr;
Quick array element existance test
![Page 14: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/14.jpg)
someth()if grep {$_ == $value} @arr;
Better than
![Page 15: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/15.jpg)
someth()if grep {$_ eq $value} @arr;
Better than
![Page 16: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/16.jpg)
someth()if grep {$value =~ $_} @arr;
Better than
![Page 17: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/17.jpg)
if ($remote_addr ~~ ['12.45.67.99', '59.44.11.33']) {...}
Quick IP address test
![Page 18: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/18.jpg)
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](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/19.jpg)
sub route { '/'}
URL match test
$page-‐>render if $url ~~ $page-‐>route;
![Page 20: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/20.jpg)
sub route { qr{^/admin/}}
URL match test
$page-‐>render if $url ~~ $page-‐>route;
![Page 21: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/21.jpg)
~~is very Perlish
![Page 22: The Joy of Smartmatch](https://reader033.fdocuments.in/reader033/viewer/2022051411/546ce88daf79597b298b51ca/html5/thumbnails/22.jpg)
Save the ~~