SlideShare une entreprise Scribd logo
1  sur  32
My Perl
Bag of Tricks
       ������
        brian d foy
      The Perl Review
     YAPC::Brasil 2011




 http://slidesha.re/s06nuv
⃠
• Eliminate special cases
• Remove distractions
• Know less
• Let Perl do the work
• Scale gracefully
% perl -e "print qq(Alo Mundon)"

% perl -le "print q(Alo Mundo)"
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( nome => '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 }
  }
������
Obrigado

http://slidesha.re/s06nuv
http://commons.wikimedia.org/wiki/File:Pelé_jump_1958.jpg




http://commons.wikimedia.org/wiki/File:Brazilian_National_Congress.jpg

Contenu connexe

Tendances

20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked aboutTatsuhiko Miyagawa
 
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
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLsAugusto Pascutti
 
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
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolveXSolve
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type Systemabrummett
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6brian d foy
 
Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8XSolve
 
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
 

Tendances (20)

20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Perl5i
Perl5iPerl5i
Perl5i
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 
PHP pod mikroskopom
PHP pod mikroskopomPHP pod mikroskopom
PHP pod mikroskopom
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
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
 
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
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
6 things about perl 6
6 things about perl 66 things about perl 6
6 things about perl 6
 
Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8
 
Functional php
Functional phpFunctional php
Functional php
 
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
 
Git avançado
Git avançadoGit avançado
Git avançado
 

En vedette

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
 
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
 
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
 
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
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new featuresbrian d foy
 
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
 
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
 
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
 

En vedette (12)

I ❤ CPAN
I ❤ CPANI ❤ CPAN
I ❤ CPAN
 
6 more things about Perl 6
6 more things about Perl 66 more things about Perl 6
6 more things about 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
 
Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6Perl Power Tools - Saint Perl 6
Perl Power Tools - Saint Perl 6
 
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
 
Perl 5.28 new features
Perl 5.28 new featuresPerl 5.28 new features
Perl 5.28 new features
 
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
 
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
 
The Whitespace in the Perl Community
The Whitespace in the Perl CommunityThe Whitespace in the Perl Community
The Whitespace in the Perl Community
 

Similaire à Bag of tricks

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
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
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHPTaras Kalapun
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationAttila Balazs
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)Yoshihiro Sugi
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perlgarux
 
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 it2shortplanks
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic trapsDamien Seguy
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs shBen Pope
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confooDamien Seguy
 

Similaire à Bag of tricks (20)

wget.pl
wget.plwget.pl
wget.pl
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
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)
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Daily notes
Daily notesDaily notes
Daily notes
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
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
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
Descobrindo a linguagem Perl
Descobrindo a linguagem PerlDescobrindo a linguagem Perl
Descobrindo a linguagem Perl
 
mro-every.pdf
mro-every.pdfmro-every.pdf
mro-every.pdf
 
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
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Top 10 php classic traps confoo
Top 10 php classic traps confooTop 10 php classic traps confoo
Top 10 php classic traps confoo
 

Plus de 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
 
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
 
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
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (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
 

Plus de brian d foy (13)

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)
 
Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)Dumping Perl 6 (French Perl Workshop)
Dumping Perl 6 (French Perl Workshop)
 
Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)Perl v5.26 Features (AmsterdamX.pm)
Perl v5.26 Features (AmsterdamX.pm)
 
Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (AmsterdamX.pm)Dumping Perl 6 (AmsterdamX.pm)
Dumping Perl 6 (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
 

Dernier

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Dernier (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Bag of tricks

  • 1. My Perl Bag of Tricks ������ brian d foy The Perl Review YAPC::Brasil 2011 http://slidesha.re/s06nuv
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. • Eliminate special cases • Remove distractions • Know less • Let Perl do the work • Scale gracefully
  • 7. % perl -e "print qq(Alo Mundon)" % perl -le "print q(Alo Mundo)"
  • 8. my $string = some_sub(); open my $fh, '<', $string; while(<$fh>){ chomp; ...; }
  • 9. use 5.014; my $new = $old =~ s/.../.../r; foo( $old =~ s/.../.../r ); print "%s %sn", $old, $old =~ s/.../.../r ;
  • 10. foreach my $file ( @files ) { open my($fh), '>', $file or do { warn "... $!n"; next FILE; }; ... }
  • 11. my $data = do { local $/; <DATA> }; ...; __END__ <?xml version="1.0"?> <root> ... </root>
  • 12. my $data = do { local $/; <DATA> }; s|.*(?=<elem>)||; s|(?<=</elem>).*||; my $name = m|<elem>(.*?)</elem>|; __END__ <?xml version="1.0"?> <root> ...<elem>Buster</elem> </root>
  • 13. $g = q("Mimi","Bean,Buster","Roscoe"); my @gatos = split /(?<="),(?=")/, $g;
  • 14. $g = q("Roscoe "","" Cat","Bean, Buster"); my @gatos = split /(?<!"")(?<="),(?=")(?!"")/, $g;
  • 15. 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// )
  • 16. join "n", @entries, ''; join "nt", "t", @entries;
  • 17. BEGIN { use Foo; package Foo; no warnings qw(redefine); sub foo { ... } }
  • 18. # Git::CPAN::Patch % git cpan-init http://... ... hack hack hack ... % git commit % git cpan-sendpatch
  • 19. my $file = MPEG::Info->new( ... ); print join $/, map { $file->$_() } qw(acodec acodecraw achans ... );
  • 20. package Modulino { run(@ARGV) unless caller; sub run { my @args = @_; ...; } }
  • 21. if( /p{IsUppercaseRoman}/ ) { ...} # ⅠⅤⅩⅬⅭⅮⅯↁↂↇↈ sub IsUppercaseRoman { return <<"CODE_NUMBERS"; 2160 2164 2169 216C 216F 2181 2182 2187 2188 CODE_NUMBERS }
  • 22. printf '%1$#b %1$#o %1$d %1$#xn", 137; # 0b10001001 0211 137 0x89
  • 23. gato( nome => 'Buster' ); sub gato { my %defaults = (...); my %config = (%defaults, @_ ); ...; }
  • 24. 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 );
  • 25. sub my_grep (&@) { my( $sub ) = shift; foreach my $arg ( @_ ) { local $_ = $arg; push @output, $arg if $sub->() } }
  • 26. my $ucfirst_and_trim = composer( &trim_front, &trim_back, &my_ucfirst ); $s = $ucfirst_and_trim->($s);
  • 27. sub composer { my (@sub_refs) = @_; sub { my $string = shift; foreach my $sub_ref (@sub_refs) { $string = $sub_ref->($string); } return $string; }; }
  • 28. 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] ); }
  • 29. 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; } ...; }
  • 30. $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 } }