SlideShare a Scribd company logo
1 of 26
My Perl 
Bag of Tricks 
brian d foy 
The Perl Review 
Baltimore Perl mongers
•Eliminate special cases 
•Remove distractions 
•Know less 
•Let Perl do the work 
•Scale gracefully
% perl -e "print qq(Hello Worldn)" 
! 
% perl -le "print q(Hello World)"
my $string = some_sub(); 
! 
open my $fh, '<', $string; 
! 
while(<$fh>){ 
chomp; 
...; 
}
use 5.014; 
! 
my $new = $old =~ s/.../.../r; 
! 
foo( $old =~ s/.../.../r ); 
! 
print "%s %sn", 
$old, 
$old =~ s/.../.../r 
;
foreach my $file ( @files ) { 
open my($fh), '>', $file or do { 
warn "... $!n"; 
next FILE; 
}; 
... 
}
my $data = do { 
local $/; <DATA> 
}; 
...; 
! 
__END__ 
<?xml version="1.0"?> 
<root> 
... 
</root>
my $data = do { local $/; <DATA> }; 
! 
s|.*(?=<elem>)||; s|(?<=</elem>).*||; 
! 
my $name = 
m|<elem>(.*?)</elem>|; 
! 
__END__ 
<?xml version="1.0"?> 
<root> 
...<elem>Buster</elem> 
</root>
$g = 
q("Mimi","Bean,Buster","Roscoe"); 
! 
my @gatos = split /(?<="),(?=")/, $g;
$g = 
q("Roscoe "","" Cat","Bean, Buster"); 
! 
my @gatos = 
split 
/(?<!"")(?<="),(?=")(?!"")/, $g;
if( ref $r eq 'ARRAY' ) 
! 
if( ref $r eq ref [] ) 
! 
if( ref $r eq ref {} ) 
! 
if( ref $r eq ref sub {} ) 
! 
if( ref $r eq ref qr// )
join "n", @entries, ''; 
! 
join "nt", "t", @entries;
BEGIN { 
use Foo; 
package Foo; 
no warnings qw(redefine); 
sub foo { ... } 
}
# Git::CPAN::Patch 
! 
% git cpan-init http://... 
... hack hack hack ... 
% git commit 
% git cpan-sendpatch
my $file = MPEG::Info->new( ... ); 
! 
print 
join $/, 
map { 
$file->$_() 
} qw(acodec 
acodecraw 
achans 
... 
);
package Modulino { 
run(@ARGV) unless caller; 
! 
sub run { 
my @args = @_; 
...; 
} 
! 
}
if( /p{IsUppercaseRoman}/ ) { 
...} 
! 
# Ⅰ Ⅴ Ⅹ Ⅼ Ⅽ Ⅾ Ⅿ ↁ ↂ ↇ ↈ 
sub IsUppercaseRoman { 
return <<"CODE_NUMBERS"; 
2160 
2164 
2169 
216C 216F 
2181 2182 
2187 2188 
CODE_NUMBERS 
}
printf 
'%1$#b %1$#o %1$d %1$#xn", 
137; 
! 
! 
# 0b10001001 0211 137 0x89
gato( name => 'Buster' ); 
! 
sub gato { 
my %defaults = (...); 
my %config = (%defaults, @_ ); 
...; 
}
BEGIN { 
my $fixed_time = 1234567890; 
no warnings qw(redefine); 
! 
*CORE::GLOBAL::time = 
sub { $fixed_time }; 
! 
sub set_time { 
$fixed_time = $_[0] 
} 
} 
! 
ok( time > $fixed_time );
sub my_grep (&@) { 
my( $sub ) = shift; 
foreach my $arg ( @_ ) { 
local $_ = $arg; 
push @output, $arg 
if $sub->() 
} 
}
my $ucfirst_and_trim = 
composer( 
&trim_front, 
&trim_back, 
&my_ucfirst 
); 
! 
$s = $ucfirst_and_trim->($s);
sub composer { 
my (@sub_refs) = @_; 
sub { 
my $string = shift; 
foreach my $sub_ref (@sub_refs) { 
$string = $sub_ref->($string); 
} 
return $string; 
}; 
}
my @tests = ( 
# ARG EXPECTED LABEL 
[ [1,2,3], 6, 'Sum is 6' ], 
[ [-1,0,9], 8, 'Sum is 8' ], 
... 
); 
! 
foreach my $test ( @tests ) { 
is( 
target_sub( $test->[ARG] ), 
$test->[EXPECTED], 
$test->[LABEL] 
); 
}
package Local::Null::Logger { 
sub new { bless  my $x, $_[0] } 
sub AUTOLOAD { shift; print @_, $/ } 
sub DESTROY { 1 } 
} 
! 
sub _init_logger { 
my $log4perl_loaded = 
eval "require Log::Log4perl; 1"; 
unless( $log4perl_loaded ){ 
return Local::Null::Logger->new; 
} 
...; 
}
$object->foo->bar->baz->quux; 
! 
package Class { 
sub bar { 
return Null->new if $error; 
} 
} 
! 
package Null { 
my $null = bless {}, __PACKAGE__; 
sub new { $null } 
sub AUTOLOAD { return $_[0] } 
sub DESTROY { 1 } 
}

More Related Content

What's hot

Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Andrew Shitov
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6brian d foy
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new featuresbrian d foy
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLsAugusto Pascutti
 
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
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type Systemabrummett
 
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 & Perl6Workhorse Computing
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)brian d foy
 
Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)brian d foy
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16Ricardo Signes
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about Perl 6brian d foy
 

What's hot (20)

Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6Text in search queries with examples in Perl 6
Text in search queries with examples in Perl 6
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new features
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Perl5i
Perl5iPerl5i
Perl5i
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
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
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about Perl 6
 
7. Lower upper in Laravel
7. Lower upper in Laravel7. Lower upper in Laravel
7. Lower upper in Laravel
 
Dades i operadors
Dades i operadorsDades i operadors
Dades i operadors
 

Viewers also liked

Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6brian d foy
 
Tour of the Perl docs
Tour of the Perl docsTour of the Perl docs
Tour of the Perl docsbrian d foy
 
Create and upload your first Perl module to CPAN
Create and upload your first Perl module to CPANCreate and upload your first Perl module to CPAN
Create and upload your first Perl module to CPANbrian d foy
 
The Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian TransformThe Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian Transformbrian d foy
 
The Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David SmileyThe Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David SmileyLucidworks
 
Making My Own CPAN
Making My Own CPANMaking My Own CPAN
Making My Own CPANbrian d foy
 
Making My Own CPAN
Making My Own CPANMaking My Own CPAN
Making My Own CPANbrian d foy
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Communitybrian d foy
 
Perl Conferences for Beginners
Perl Conferences for BeginnersPerl Conferences for Beginners
Perl Conferences for Beginnersbrian d foy
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014brian d foy
 
Improving the Solr Update Chain
Improving the Solr Update ChainImproving the Solr Update Chain
Improving the Solr Update ChainCominvent AS
 

Viewers also liked (12)

I ❤ CPAN
I ❤ CPANI ❤ CPAN
I ❤ CPAN
 
Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6
 
Tour of the Perl docs
Tour of the Perl docsTour of the Perl docs
Tour of the Perl docs
 
Create and upload your first Perl module to CPAN
Create and upload your first Perl module to CPANCreate and upload your first Perl module to CPAN
Create and upload your first Perl module to CPAN
 
The Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian TransformThe Surprisingly Tense History of the Schwartzian Transform
The Surprisingly Tense History of the Schwartzian Transform
 
The Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David SmileyThe Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David Smiley
 
Making My Own CPAN
Making My Own CPANMaking My Own CPAN
Making My Own CPAN
 
Making My Own CPAN
Making My Own CPANMaking My Own CPAN
Making My Own CPAN
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Community
 
Perl Conferences for Beginners
Perl Conferences for BeginnersPerl Conferences for Beginners
Perl Conferences for Beginners
 
CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014CPAN Workshop, Chicago 2014
CPAN Workshop, Chicago 2014
 
Improving the Solr Update Chain
Improving the Solr Update ChainImproving the Solr Update Chain
Improving the Solr Update Chain
 

Similar to Perl Bag of Tricks - Baltimore Perl mongers

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perlgarux
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl styleBo Hua Yang
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたTakeshi Arabiki
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
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)Michael Schwern
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationAttila Balazs
 
Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)osfameron
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 

Similar to Perl Bag of Tricks - Baltimore Perl mongers (20)

Modern Perl
Modern PerlModern Perl
Modern Perl
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
wget.pl
wget.plwget.pl
wget.pl
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
 
Tgh.pl
Tgh.plTgh.pl
Tgh.pl
 
Ae internals
Ae internalsAe internals
Ae internals
 
Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01Barcelona.pm Curs1211 sess01
Barcelona.pm Curs1211 sess01
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
spug_2008-08
spug_2008-08spug_2008-08
spug_2008-08
 
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)
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 

More from brian d foy

Conferences for Beginners presentation
Conferences for Beginners presentationConferences for Beginners presentation
Conferences for Beginners presentationbrian d foy
 
20 years in Perl
20 years in Perl20 years in Perl
20 years in Perlbrian d foy
 
PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)brian d foy
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)brian d foy
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPANbrian d foy
 
Backward to DPAN
Backward to DPANBackward to DPAN
Backward to DPANbrian d foy
 
Perl docs {sux|rulez}
Perl docs {sux|rulez}Perl docs {sux|rulez}
Perl docs {sux|rulez}brian d foy
 
What's wrong with the perldocs
What's wrong with the perldocsWhat's wrong with the perldocs
What's wrong with the perldocsbrian d foy
 
Frozen Perl 2011 Keynote
Frozen Perl 2011 KeynoteFrozen Perl 2011 Keynote
Frozen Perl 2011 Keynotebrian d foy
 

More from brian d foy (11)

Conferences for Beginners presentation
Conferences for Beginners presentationConferences for Beginners presentation
Conferences for Beginners presentation
 
20 years in Perl
20 years in Perl20 years in Perl
20 years in Perl
 
PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)PrettyDump Perl 6 (London.pm)
PrettyDump Perl 6 (London.pm)
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)
 
Reverse Installing CPAN
Reverse Installing CPANReverse Installing CPAN
Reverse Installing CPAN
 
Backward to DPAN
Backward to DPANBackward to DPAN
Backward to DPAN
 
Perl docs {sux|rulez}
Perl docs {sux|rulez}Perl docs {sux|rulez}
Perl docs {sux|rulez}
 
Why I Love CPAN
Why I Love CPANWhy I Love CPAN
Why I Love CPAN
 
What's wrong with the perldocs
What's wrong with the perldocsWhat's wrong with the perldocs
What's wrong with the perldocs
 
Frozen Perl 2011 Keynote
Frozen Perl 2011 KeynoteFrozen Perl 2011 Keynote
Frozen Perl 2011 Keynote
 
brian d foy
brian d foybrian d foy
brian d foy
 

Recently uploaded

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxMarkSteadman7
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...caitlingebhard1
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingWSO2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 

Recently uploaded (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 

Perl Bag of Tricks - Baltimore Perl mongers

  • 1. My Perl Bag of Tricks brian d foy The Perl Review Baltimore Perl mongers
  • 2. •Eliminate special cases •Remove distractions •Know less •Let Perl do the work •Scale gracefully
  • 3. % perl -e "print qq(Hello Worldn)" ! % perl -le "print q(Hello World)"
  • 4. my $string = some_sub(); ! open my $fh, '<', $string; ! while(<$fh>){ chomp; ...; }
  • 5. use 5.014; ! my $new = $old =~ s/.../.../r; ! foo( $old =~ s/.../.../r ); ! print "%s %sn", $old, $old =~ s/.../.../r ;
  • 6. foreach my $file ( @files ) { open my($fh), '>', $file or do { warn "... $!n"; next FILE; }; ... }
  • 7. my $data = do { local $/; <DATA> }; ...; ! __END__ <?xml version="1.0"?> <root> ... </root>
  • 8. my $data = do { local $/; <DATA> }; ! s|.*(?=<elem>)||; s|(?<=</elem>).*||; ! my $name = m|<elem>(.*?)</elem>|; ! __END__ <?xml version="1.0"?> <root> ...<elem>Buster</elem> </root>
  • 9. $g = q("Mimi","Bean,Buster","Roscoe"); ! my @gatos = split /(?<="),(?=")/, $g;
  • 10. $g = q("Roscoe "","" Cat","Bean, Buster"); ! my @gatos = split /(?<!"")(?<="),(?=")(?!"")/, $g;
  • 11. if( ref $r eq 'ARRAY' ) ! if( ref $r eq ref [] ) ! if( ref $r eq ref {} ) ! if( ref $r eq ref sub {} ) ! if( ref $r eq ref qr// )
  • 12. join "n", @entries, ''; ! join "nt", "t", @entries;
  • 13. BEGIN { use Foo; package Foo; no warnings qw(redefine); sub foo { ... } }
  • 14. # Git::CPAN::Patch ! % git cpan-init http://... ... hack hack hack ... % git commit % git cpan-sendpatch
  • 15. my $file = MPEG::Info->new( ... ); ! print join $/, map { $file->$_() } qw(acodec acodecraw achans ... );
  • 16. package Modulino { run(@ARGV) unless caller; ! sub run { my @args = @_; ...; } ! }
  • 17. if( /p{IsUppercaseRoman}/ ) { ...} ! # Ⅰ Ⅴ Ⅹ Ⅼ Ⅽ Ⅾ Ⅿ ↁ ↂ ↇ ↈ sub IsUppercaseRoman { return <<"CODE_NUMBERS"; 2160 2164 2169 216C 216F 2181 2182 2187 2188 CODE_NUMBERS }
  • 18. printf '%1$#b %1$#o %1$d %1$#xn", 137; ! ! # 0b10001001 0211 137 0x89
  • 19. gato( name => 'Buster' ); ! sub gato { my %defaults = (...); my %config = (%defaults, @_ ); ...; }
  • 20. BEGIN { my $fixed_time = 1234567890; no warnings qw(redefine); ! *CORE::GLOBAL::time = sub { $fixed_time }; ! sub set_time { $fixed_time = $_[0] } } ! ok( time > $fixed_time );
  • 21. sub my_grep (&@) { my( $sub ) = shift; foreach my $arg ( @_ ) { local $_ = $arg; push @output, $arg if $sub->() } }
  • 22. my $ucfirst_and_trim = composer( &trim_front, &trim_back, &my_ucfirst ); ! $s = $ucfirst_and_trim->($s);
  • 23. sub composer { my (@sub_refs) = @_; sub { my $string = shift; foreach my $sub_ref (@sub_refs) { $string = $sub_ref->($string); } return $string; }; }
  • 24. my @tests = ( # ARG EXPECTED LABEL [ [1,2,3], 6, 'Sum is 6' ], [ [-1,0,9], 8, 'Sum is 8' ], ... ); ! foreach my $test ( @tests ) { is( target_sub( $test->[ARG] ), $test->[EXPECTED], $test->[LABEL] ); }
  • 25. package Local::Null::Logger { sub new { bless my $x, $_[0] } sub AUTOLOAD { shift; print @_, $/ } sub DESTROY { 1 } } ! sub _init_logger { my $log4perl_loaded = eval "require Log::Log4perl; 1"; unless( $log4perl_loaded ){ return Local::Null::Logger->new; } ...; }
  • 26. $object->foo->bar->baz->quux; ! package Class { sub bar { return Null->new if $error; } } ! package Null { my $null = bless {}, __PACKAGE__; sub new { $null } sub AUTOLOAD { return $_[0] } sub DESTROY { 1 } }