Upload
andysh
View
596
Download
2
Embed Size (px)
DESCRIPTION
Citation preview
The Joyof Smart Match
The Joyof Smartmatch
The Joyof ~~
Introduced in Perl 5.10
Introduced in 2007
How it was initially designed
How it is proposed to be
How it looks like now
no 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'], [['ADMIN', 'OWNER'], 'USER' ] ]) { $loaded_user-‐>create($editable_user)}
Someone's similar usage
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 ~~