SlideShare a Scribd company logo
1 of 23
Download to read offline
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 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 ~~
__END__
Andrew Shitov andy@shitov.ru
May 2013

More Related Content

What's hot

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 

What's hot (20)

Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
Perl 6 in Context
Perl 6 in ContextPerl 6 in Context
Perl 6 in Context
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Perl6 one-liners
Perl6 one-linersPerl6 one-liners
Perl6 one-liners
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 

Similar to The Joy of Smartmatch

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Advance Techniques In Php
Advance Techniques In PhpAdvance Techniques In Php
Advance Techniques In Php
Kumar S
 
AST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptAST - the only true tool for building JavaScript
AST - the only true tool for building JavaScript
Ingvar Stepanyan
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 

Similar to The Joy of Smartmatch (20)

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
Groovy
GroovyGroovy
Groovy
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Lucene
LuceneLucene
Lucene
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Advance Techniques In Php
Advance Techniques In PhpAdvance Techniques In Php
Advance Techniques In Php
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Perl Sucks - and what to do about it
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
AST - the only true tool for building JavaScript
AST - the only true tool for building JavaScriptAST - the only true tool for building JavaScript
AST - the only true tool for building JavaScript
 
PHP Conference Asia 2016
PHP Conference Asia 2016PHP Conference Asia 2016
PHP Conference Asia 2016
 
Practical Testing of Ruby Core
Practical Testing of Ruby CorePractical Testing of Ruby Core
Practical Testing of Ruby Core
 
Wakanday JS201 Best Practices
Wakanday JS201 Best PracticesWakanday JS201 Best Practices
Wakanday JS201 Best Practices
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Evolving Tests
Evolving TestsEvolving Tests
Evolving Tests
 
Power shell voor developers
Power shell voor developersPower shell voor developers
Power shell voor developers
 

More from Andrew Shitov

‎Откуда узнать про Perl 6‎
‎Откуда узнать про Perl 6‎‎Откуда узнать про Perl 6‎
‎Откуда узнать про Perl 6‎
Andrew Shitov
 
‎42 £ в ойрах‎
‎42 £ в ойрах‎‎42 £ в ойрах‎
‎42 £ в ойрах‎
Andrew Shitov
 
10 мероприятий за 20 месяцев в пяти странах
10 мероприятий за 20 месяцев в пяти странах10 мероприятий за 20 месяцев в пяти странах
10 мероприятий за 20 месяцев в пяти странах
Andrew Shitov
 

More from Andrew Shitov (20)

Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)Fun with Raspberry PI (and Perl)
Fun with Raspberry PI (and Perl)
 
Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6Параллельные вычисления в Perl 6
Параллельные вычисления в Perl 6
 
AllPerlBooks.com
AllPerlBooks.comAllPerlBooks.com
AllPerlBooks.com
 
YAPC::Europe 2013
YAPC::Europe 2013YAPC::Europe 2013
YAPC::Europe 2013
 
Perl 7, the story of
Perl 7, the story ofPerl 7, the story of
Perl 7, the story of
 
Язык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистовЯзык программирования Go для Perl-программистов
Язык программирования Go для Perl-программистов
 
Как очистить массив
Как очистить массивКак очистить массив
Как очистить массив
 
What's new in Perl 5.14
What's new in Perl 5.14What's new in Perl 5.14
What's new in Perl 5.14
 
Что нового в Perl 5.14
Что нового в Perl 5.14Что нового в Perl 5.14
Что нового в Perl 5.14
 
There's more than one way to empty it
There's more than one way to empty itThere's more than one way to empty it
There's more than one way to empty it
 
How to clean an array
How to clean an arrayHow to clean an array
How to clean an array
 
Perl 5.10 и 5.12
Perl 5.10 и 5.12Perl 5.10 и 5.12
Perl 5.10 и 5.12
 
Say Perl на весь мир
Say Perl на весь мирSay Perl на весь мир
Say Perl на весь мир
 
Personal Perl 6 compiler
Personal Perl 6 compilerPersonal Perl 6 compiler
Personal Perl 6 compiler
 
Perl 5.10 in 2010
Perl 5.10 in 2010Perl 5.10 in 2010
Perl 5.10 in 2010
 
Perl 5.10 в 2010-м
Perl 5.10 в 2010-мPerl 5.10 в 2010-м
Perl 5.10 в 2010-м
 
Gearman and Perl
Gearman and PerlGearman and Perl
Gearman and Perl
 
‎Откуда узнать про Perl 6‎
‎Откуда узнать про Perl 6‎‎Откуда узнать про Perl 6‎
‎Откуда узнать про Perl 6‎
 
‎42 £ в ойрах‎
‎42 £ в ойрах‎‎42 £ в ойрах‎
‎42 £ в ойрах‎
 
10 мероприятий за 20 месяцев в пяти странах
10 мероприятий за 20 месяцев в пяти странах10 мероприятий за 20 месяцев в пяти странах
10 мероприятий за 20 месяцев в пяти странах
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

The Joy of Smartmatch