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 Smart Match
The Joy
of Smartmatch
The Joy
of ~~
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 addre...
if	
  ([$loaded_user,	
  $editable_user]	
  ~~
	
  	
  	
  	
  [
	
  	
  	
  	
  	
  	
  [	
  'OWNER',	
  	
  	
  	
  	
  ...
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 ~~
__END__
Andrew Shitov andy@shitov.ru
May 2013
The Joy of Smartmatch
The Joy of Smartmatch
Upcoming SlideShare
Loading in …5
×

of

The Joy of Smartmatch Slide 1 The Joy of Smartmatch Slide 2 The Joy of Smartmatch Slide 3 The Joy of Smartmatch Slide 4 The Joy of Smartmatch Slide 5 The Joy of Smartmatch Slide 6 The Joy of Smartmatch Slide 7 The Joy of Smartmatch Slide 8 The Joy of Smartmatch Slide 9 The Joy of Smartmatch Slide 10 The Joy of Smartmatch Slide 11 The Joy of Smartmatch Slide 12 The Joy of Smartmatch Slide 13 The Joy of Smartmatch Slide 14 The Joy of Smartmatch Slide 15 The Joy of Smartmatch Slide 16 The Joy of Smartmatch Slide 17 The Joy of Smartmatch Slide 18 The Joy of Smartmatch Slide 19 The Joy of Smartmatch Slide 20 The Joy of Smartmatch Slide 21 The Joy of Smartmatch Slide 22 The Joy of Smartmatch Slide 23
Upcoming SlideShare
AllPerlBooks.com
Next
Download to read offline and view in fullscreen.

0 Likes

Share

Download to read offline

The Joy of Smartmatch

Download to read offline

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

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

Views

Total views

1,176

On Slideshare

0

From embeds

0

Number of embeds

106

Actions

Downloads

6

Shares

0

Comments

0

Likes

0

×