SlideShare ist ein Scribd-Unternehmen logo
1 von 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 } 
}

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Kürzlich hochgeladen (20)

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

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 } }