SlideShare a Scribd company logo
josh mcadams
doubleclick/performics
use strict;
use strict;


  $perl = 'frozen';
  $ref = 'perl';
  print $$ref, quot;nquot;;

$ perl strict_refs.pl
frozen
use strict;


                  use strict quot;refsquot;;
                  $perl = 'frozen';
                  $ref = 'perl';
                  print $$ref, quot;nquot;;


$ perl strict_refs.pl
Can't use string (quot;perlquot;) as a SCALAR ref while quot;strict refsquot; in use
at strict_refs.pl line 4.
use strict;


                      use strict quot;varsquot;;
                      $perl = 'frozen';
                      $ref = 'perl';
                      print $$ref, quot;nquot;;

$ perl strict_vars.pl
Global symbol quot;$perlquot; requires explicit package name at strict_vars.pl line 2.
Global symbol quot;$refquot; requires explicit package name at strict_vars.pl line 3.
Global symbol quot;$refquot; requires explicit package name at strict_vars.pl line 4.
Execution of strict_vars.pl aborted due to compilation errors.
use strict;


use strict quot;varsquot;;
our $perl = 'frozen';
my $ref   = 'perl';
print $$ref, quot;nquot;;

$ perl strict_vars.pl
frozen
use strict;


use strict quot;subsquot;;
$person = Josh;
$directory{mcadams} = [ first => $person ];
print $directory{mcadams}->[1], quot;nquot;;


$ perl strict_subs.pl
Bareword quot;Joshquot; not allowed while quot;strict subsquot; in use at
strict_subs.pl line 2.
Execution of strict_subs.pl aborted due to compilation errors.
use strict;


use strict quot;subsquot;;
$person = ‘Josh’;
$directory{mcadams} = [ first => $person ];
print $directory{mcadams}->[1], quot;nquot;;



          $ perl strict_subs.pl
          Josh
use strict;




- Typically ‘use strict;’ is all that you’ll need

- You can ‘no strict “refs”;’ in your code

- Use the strict pragma in all of your Perl code
use warnings;
use warnings;




perl -w script.pl

#/usr/bin/perl -w
use warnings;




use warnings;

no warnings;
use base;
use base;




push @ISA, ‘SomeModule’;
use base;




use base qw(SomeModule);
use constant;
use constant;



use warnings;
use strict;
use constant DO_NOT_DISTURB => 1;

print quot;leave me alonenquot; if DO_NOT_DISTURB;


> perl constant.pl
leave me alone
use Exporter;
use Exporter;




use MyPackage;

MyPackage::my_subroutine();
use Exporter;

package MyPackage;

use warnings;
use strict;
use Exporter qw(import);

our @EXPORT_OK = qw(my_subroutine);

sub my_subroutine {
    print quot;hellonquot;;
}

1;
use Exporter;




use warnings;
use strict;
use MyPackage qw(my_subroutine);

my_subroutine();
use Data::Dumper;
use Data::Dumper;


use warnings;
use strict;
use Data::Dumper;

print Dumper @ARGV;

> perl datadumper.pl hello frozen perl
$VAR1 = [
           'hello',
           'frozen',
           'perl'
        ];
use Class::Accessor;
use Class::Accessor;




sub name {
  my ($self, $value) = @_;
  $self->{name} = $value if $value;
  return $self->{name};
}
use Class::Accessor;




package MyClass;
use base qw(Class::Accessor);
__PACKAGE__->mk_accessors(qw(name));
use Carp;
use Carp;

 1   package PackageOne;
 2
 3   sub y { z(); }
 4   sub z { die('oops'); }
 5
 6   package PackageTwo;
                                  $ perl die.pl
 7
                                  oops at die.pl line 4.
 8   sub a { b(); }
 9   sub b { PackageOne::y(); }
10
11   package main;
12
13   PackageTwo::a();
use Carp;

 1   package PackageOne;
 2
 3   use Carp;
 4
 5   sub y { z(); }
 6   sub z { croak('oops'); }
 7
                                  $ perl croak.pl
 8   package PackageTwo;          oops at croak.pl line 11
 9
10   sub a { b(); }
11   sub b { PackageOne::y(); }
12
13   package main;
14
15   PackageTwo::a();
use Carp;

 1   package PackageOne;
 2
 3   use Carp qw(confess);
 4                                $ perl confess.pl
 5   sub y { z(); }               oops at confess.pl line   6
 6   sub z { confess('oops'); }    PackageOne::z() called   at
 7                                  confess.pl line 5
                                   PackageOne::y() called   at
 8   package PackageTwo;            confess.pl line 11
 9                                 PackageTwo::b() called   at
10   sub a { b(); }                 confess.pl line 10
11   sub b { PackageOne::y(); }    PackageTwo::a() called   at
12                                  confess.pl line 15
13   package main;
14
15   PackageTwo::a();
use Carp;

             caller’s
standard                 full stacktrace
           perspective



 warn         carp           cluck




  die         croak         confess
use Carp::Assert;
use Carp::Assert;

use Carp::Assert;

assert( 1 > 0 );

affirm {
    my $name = 'Josh';
    my @attendees = qw( Josh Heather Addy );
    grep { $_ eq $name } @attendees;
}


> perl assert.pl
use Carp::Assert;

use Carp::Assert;

assert( 1 > 2);

affirm {
    my $name = 'Josh';
    my @attendees = qw( Josh Heather Addy );
    grep { $_ eq $name } @attendees;
}

> perl assert.pl
Assertion failed!
 at /opt/local/lib/perl5/site_perl/5.8.8/Carp/Assert.pm line 281
        Carp::Assert::assert('') called at assert.pl line 5
use Carp::Assert;

use Carp::Assert;

assert( 1 > 0);

affirm {
    my $name = 'Joshua';
    my @attendees = qw( Josh Heather Addy );
    grep { $_ eq $name } @attendees;
}
> perl assert.pl
Assertion ({
    use warnings;
    use strict 'refs';
    my $name = 'Joshua';
    my(@attendees) = ('Josh', 'Heather', 'Addy');
    grep {$_ eq $name;} @attendees;
}) failed!
 at /opt/local/lib/perl5/site_perl/5.8.8/Carp/Assert.pm line 340
        Carp::Assert::affirm('CODE(0x1800ee0)') called at assert.pl line 11
use File::Spec;
use File::Spec;

use warnings;
use strict;
use File::Spec;

my @dirs = File::Spec->splitdir($0);
print '[', join('][', @dirs), quot;]nquot;;
my $dir = File::Spec->join(@dirs);
print $dir, quot;nquot;;
> perl /Users/joshua/examples/filespec.pl
[][Users][joshua][examples][filespec.pl]
/Users/joshua/examples/filespec.pl
use File::stat;
use File::stat;




my ($dev,$ino,$mode,$nlink,$uid,
$gid,$rdev,$size,$atime,$mtime,
$ctime,$blksize,$blocks) = stat
($filename);
use File::stat;


use warnings;
use strict;
use File::stat;

my $s = stat($0);

print $s->size, quot;nquot;;
> perl filestat.pl
84
use File::Slurp;
use File::Slurp;



{
    local(*INPUT, $/);
    open (INPUT, $file)
     || die quot;can't open $file: $!quot;;
    $var = <INPUT>;
}
use File::Slurp;




my $text = read_file( $file );
my @lines = read_file( $file );
use File::Slurp;




write_file( $filename, @data );
use File::Copy;
use File::Copy;



use warnings;
use strict;
use File::Copy;

my $command = quot;cp $0 $0.bkupquot;;
`$command`;
use File::Copy;



use warnings;
use strict;
use File::Copy;

copy $0, $0 . '.bkup' or die $!;
use File::Temp;
use File::Temp;

use warnings;
use strict;
use File::Temp;

my $fh = File::Temp->new( UNLINK => 1 );

print $fh->filename, quot;nquot;;


> perl tempfile.pl
/tmp/yZin81tl6z
use File::Temp;

use warnings;
use strict;
use File::Temp;

my $fh = File::Temp->newdir( CLEANUP => 1 );

print $fh->dirname, quot;nquot;;


> perl tempdir.pl
/tmp/HggvehyAyw
use File::Find;
use File::Find;


use warnings;
use strict;
use File::Find;

find( sub { print quot;$File::Find::namenquot; },
       '/Users/joshua/' );



           > perl filefind.pl
           /Users/joshua/...
use File::Next;
use File::Next;

use warnings;
use strict;
use File::Next;

my $files = File::Next::files( '/Users/joshua/' );

while ( defined ( my $file = $files->() ) ) {
    print quot;$filenquot;;
}



             > perl filenext.pl
             /Users/joshua/...
use File::Basename;
use File::Basename;
use warnings;
use strict;
use File::Basename;

my $file = basename $0;
my $path = dirname $0;
my ($file2, $path2) = fileparse $0;

print join(quot;nquot;, $file, $path,
              $file2, $path2), quot;nquot;;

  > perl /Users/joshua/examples/basename.pl
  basename.pl
  /Users/joshua/examples
  basename.pl
  /Users/joshua/examples/
use File::HomeDir;
use File::HomeDir;


 use warnings;
 use strict;
 use File::HomeDir;

 print File::HomeDir->my_home(), quot;nquot;;
 print File::HomeDir->my_data(), quot;nquot;;


> perl filehomedir.pl
/Users/joshua
/Users/joshua/Library/Application Support
use IO::File;
use IO::File;




use warnings;
use strict;

my $fh;
open( $fh, '<', $0 ) or die $!;
print while(<$fh>);
close $fh;
use IO::File;




use warnings;
use strict;
use IO::File;

my $fh = IO::File->new( $0, 'r' );
print while(<$fh>);
$fh->close;
use FindBin;
use FindBin;



package MyModule;

use warnings;
use strict;

sub hello {
    print quot;hellonquot;;
}

1;
use FindBin;


use   warnings;
use   strict;
use   lib 'mylib';
use   MyModule;

MyModule::hello();


> perl findbin.pl
hello
use FindBin;



> perl ~/bin/findbin.pl
Can't locate MyModule.pm in @INC (@INC contains: mylib /
opt/local/lib/perl5/5.8.8/darwin-2level /opt/local/lib/
perl5/5.8.8 /opt/local/lib/perl5/site_perl/5.8.8/
darwin-2level /opt/local/lib/perl5/site_perl/5.8.8 /opt/
local/lib/perl5/site_perl /opt/local/lib/perl5/
vendor_perl/5.8.8/darwin-2level /opt/local/lib/perl5/
vendor_perl/5.8.8 /opt/local/lib/perl5/vendor_perl .) at
Utility Modules That You Should Know About/findbin.pl line
4.
BEGIN failed--compilation aborted at Utility Modules That
You Should Know About/findbin.pl line 4.
use FindBin;



use   warnings;
use   strict;
use   FindBin;
use   lib quot;$FindBin::Bin/../mylibquot;;
use   MyModule;

MyModule::hello();
use Getopt::Long;
use Getopt::Long;
          use Getopt::Long;

          GetOptions(
              'greeting=s',
              'person=s',
              'prefix:s' ) or die('error');

          print join( q[ ],
              $opt_greeting,
              ($opt_prefix || q[]),
              $opt_person), quot;nquot;;


> perl getopt1.pl --greeting=hello --person=josh --prefix=
hello josh
use Getopt::Long;

use warnings;
use strict;
use Getopt::Long;

my ($greeting, $person, $prefix);
GetOptions(
    'greeting=s' => $greeting,
    'person=s'   => $person,
    'prefix:s'   => $prefix,
) or die('error');

print join( q[ ],
    $greeting,
    ($prefix || q[]),
    $person), quot;nquot;;
use Getopt::Long;

use warnings;
use strict;
use Getopt::Long;

my %options;
GetOptions( %options,
    'greeting=s',
    'person=s',
    'prefix:s',
) or die('error');

print join( q[ ],
  @options{
    qw(greeting prefix person)
    } ),
  quot;nquot;;
use Pod::Usage;
use Pod::Usage;



use Getopt::Long;
use Pod::Usage;

GetOptions('help', 'man') or pod2usage(2);
pod2usage(1) if $opt_help;
pod2usage(-verbose => 2) if $opt_man;

__END__
use Pod::Usage;
=head1 NAME

sample - Using GetOpt::Long and Pod::Usage

=head1 SYNOPSIS

sample [options]

   Options:
   -help             brief help message
   -man              full documentation

=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-man>

Prints the manual page and exits.

=back

=head1 DESCRIPTION

Sample is exactly that, a sample.

=cut
use Pod::Usage;



> perl pod_usage.pl -h
Usage:
    pod_usage [options]

        Options:
        -help             brief help message
        -man              full documentation

Options:
    -help   Print a brief help message and exits.

    -man    Prints the manual page and exits.
use Pod::Usage;
> perl pod_usage.pl -m
POD_USAGE(1)           User Contributed Perl Documentation         POD_USAGE(1)



NAME
          pod_usage - Using GetOpt::Long and Pod::Usage

SYNOPSIS
       pod_usage [options]

                 Options:
                 -help           brief help message
                 -man            full documentation

OPTIONS
          -help      Print a brief help message and exits.

          -man       Prints the manual page and exits.

DESCRIPTION
       pod_usage just an example.



perl v5.8.8                            2008-02-16                  POD_USAGE(1)
thank you
yapc.org/America

More Related Content

What's hot

Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlHideaki Ohno
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
Andrew Shitov
 
Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.
Workhorse Computing
 
Short Introduction To "perl -d"
Short Introduction To "perl -d"Short Introduction To "perl -d"
Short Introduction To "perl -d"
Workhorse Computing
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
Workhorse Computing
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
Andrew Shitov
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
Workhorse Computing
 
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
2shortplanks
 
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
heumann
 
Smolder @Silex
Smolder @SilexSmolder @Silex
Smolder @SilexJeen Lee
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.
Workhorse Computing
 
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 new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5Tom Corrigan
 
vfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsvfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent tests
Frank Kleine
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
daoswald
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Aheadthinkphp
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking Sebastian Marek
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
Takeshi Arabiki
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
Augusto Pascutti
 

What's hot (20)

Yapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed PerlYapcasia2011 - Hello Embed Perl
Yapcasia2011 - Hello Embed Perl
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.Keeping objects healthy with Object::Exercise.
Keeping objects healthy with Object::Exercise.
 
Short Introduction To "perl -d"
Short Introduction To "perl -d"Short Introduction To "perl -d"
Short Introduction To "perl -d"
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
 
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
 
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
 
Smolder @Silex
Smolder @SilexSmolder @Silex
Smolder @Silex
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5
 
vfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsvfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent tests
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
 
PHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look AheadPHP 5.3 And PHP 6 A Look Ahead
PHP 5.3 And PHP 6 A Look Ahead
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
Melhorando sua API com DSLs
Melhorando sua API com DSLsMelhorando sua API com DSLs
Melhorando sua API com DSLs
 

Similar to Utility Modules That You Should Know About

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
Ricardo Signes
 
Cleancode
CleancodeCleancode
Cleancode
hendrikvb
 
Subroutines
SubroutinesSubroutines
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
OlinData
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to do
Puppet
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
Walter Heck
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
Sanjeev Kumar Jaiswal
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationAttila Balazs
 
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
brian d foy
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門lestrrat
 
Development and practical use of CLI in perl 6
Development and practical use of CLI in perl 6Development and practical use of CLI in perl 6
Development and practical use of CLI in perl 6
risou
 
Path::Tiny
Path::TinyPath::Tiny
Path::Tiny
waniji
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
Flavio Poletti
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
Puppet
 
Augeas @RMLL 2012
Augeas @RMLL 2012Augeas @RMLL 2012
Augeas @RMLL 2012
Raphaël PINSON
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
brian d foy
 
Perl from the ground up: objects and testing
Perl from the ground up: objects and testingPerl from the ground up: objects and testing
Perl from the ground up: objects and testing
Shmuel Fomberg
 
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
Jeff Carouth
 

Similar to Utility Modules That You Should Know About (20)

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
 
Cleancode
CleancodeCleancode
Cleancode
 
Subroutines
SubroutinesSubroutines
Subroutines
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to do
 
PuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with PuppetPuppetCamp Ghent - What Not to Do with Puppet
PuppetCamp Ghent - What Not to Do with Puppet
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
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
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 
Perl5i
Perl5iPerl5i
Perl5i
 
Development and practical use of CLI in perl 6
Development and practical use of CLI in perl 6Development and practical use of CLI in perl 6
Development and practical use of CLI in perl 6
 
Path::Tiny
Path::TinyPath::Tiny
Path::Tiny
 
Perl Web Client
Perl Web ClientPerl Web Client
Perl Web Client
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
 
Augeas @RMLL 2012
Augeas @RMLL 2012Augeas @RMLL 2012
Augeas @RMLL 2012
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Advanced modulinos trial
Advanced modulinos trialAdvanced modulinos trial
Advanced modulinos trial
 
Perl from the ground up: objects and testing
Perl from the ground up: objects and testingPerl from the ground up: objects and testing
Perl from the ground up: objects and testing
 
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
 

More from joshua.mcadams

Open Flash Chart And Perl
Open Flash Chart And PerlOpen Flash Chart And Perl
Open Flash Chart And Perljoshua.mcadams
 
Introduction To Testing With Perl
Introduction To Testing With PerlIntroduction To Testing With Perl
Introduction To Testing With Perl
joshua.mcadams
 
Thank A Cpan Contributor Today
Thank A Cpan Contributor TodayThank A Cpan Contributor Today
Thank A Cpan Contributor Today
joshua.mcadams
 
YAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl CodingYAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl Coding
joshua.mcadams
 
YAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl CriticYAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl Critic
joshua.mcadams
 
YAPC::NA 2007 - An Introduction To Perl Critic
YAPC::NA 2007 - An Introduction To Perl CriticYAPC::NA 2007 - An Introduction To Perl Critic
YAPC::NA 2007 - An Introduction To Perl Critic
joshua.mcadams
 
Extending Perl Critic
Extending Perl CriticExtending Perl Critic
Extending Perl Critic
joshua.mcadams
 
An Introduction To Perl Critic
An Introduction To Perl CriticAn Introduction To Perl Critic
An Introduction To Perl Critic
joshua.mcadams
 
Lightning Talk: An Introduction To Scrum
Lightning Talk: An Introduction To ScrumLightning Talk: An Introduction To Scrum
Lightning Talk: An Introduction To Scrum
joshua.mcadams
 

More from joshua.mcadams (9)

Open Flash Chart And Perl
Open Flash Chart And PerlOpen Flash Chart And Perl
Open Flash Chart And Perl
 
Introduction To Testing With Perl
Introduction To Testing With PerlIntroduction To Testing With Perl
Introduction To Testing With Perl
 
Thank A Cpan Contributor Today
Thank A Cpan Contributor TodayThank A Cpan Contributor Today
Thank A Cpan Contributor Today
 
YAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl CodingYAPC::NA 2007 - Epic Perl Coding
YAPC::NA 2007 - Epic Perl Coding
 
YAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl CriticYAPC::NA 2007 - Customizing And Extending Perl Critic
YAPC::NA 2007 - Customizing And Extending Perl Critic
 
YAPC::NA 2007 - An Introduction To Perl Critic
YAPC::NA 2007 - An Introduction To Perl CriticYAPC::NA 2007 - An Introduction To Perl Critic
YAPC::NA 2007 - An Introduction To Perl Critic
 
Extending Perl Critic
Extending Perl CriticExtending Perl Critic
Extending Perl Critic
 
An Introduction To Perl Critic
An Introduction To Perl CriticAn Introduction To Perl Critic
An Introduction To Perl Critic
 
Lightning Talk: An Introduction To Scrum
Lightning Talk: An Introduction To ScrumLightning Talk: An Introduction To Scrum
Lightning Talk: An Introduction To Scrum
 

Recently uploaded

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 

Recently uploaded (20)

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 

Utility Modules That You Should Know About

  • 3. use strict; $perl = 'frozen'; $ref = 'perl'; print $$ref, quot;nquot;; $ perl strict_refs.pl frozen
  • 4. use strict; use strict quot;refsquot;; $perl = 'frozen'; $ref = 'perl'; print $$ref, quot;nquot;; $ perl strict_refs.pl Can't use string (quot;perlquot;) as a SCALAR ref while quot;strict refsquot; in use at strict_refs.pl line 4.
  • 5. use strict; use strict quot;varsquot;; $perl = 'frozen'; $ref = 'perl'; print $$ref, quot;nquot;; $ perl strict_vars.pl Global symbol quot;$perlquot; requires explicit package name at strict_vars.pl line 2. Global symbol quot;$refquot; requires explicit package name at strict_vars.pl line 3. Global symbol quot;$refquot; requires explicit package name at strict_vars.pl line 4. Execution of strict_vars.pl aborted due to compilation errors.
  • 6. use strict; use strict quot;varsquot;; our $perl = 'frozen'; my $ref = 'perl'; print $$ref, quot;nquot;; $ perl strict_vars.pl frozen
  • 7. use strict; use strict quot;subsquot;; $person = Josh; $directory{mcadams} = [ first => $person ]; print $directory{mcadams}->[1], quot;nquot;; $ perl strict_subs.pl Bareword quot;Joshquot; not allowed while quot;strict subsquot; in use at strict_subs.pl line 2. Execution of strict_subs.pl aborted due to compilation errors.
  • 8. use strict; use strict quot;subsquot;; $person = ‘Josh’; $directory{mcadams} = [ first => $person ]; print $directory{mcadams}->[1], quot;nquot;; $ perl strict_subs.pl Josh
  • 9. use strict; - Typically ‘use strict;’ is all that you’ll need - You can ‘no strict “refs”;’ in your code - Use the strict pragma in all of your Perl code
  • 11. use warnings; perl -w script.pl #/usr/bin/perl -w
  • 14. use base; push @ISA, ‘SomeModule’;
  • 15. use base; use base qw(SomeModule);
  • 17. use constant; use warnings; use strict; use constant DO_NOT_DISTURB => 1; print quot;leave me alonenquot; if DO_NOT_DISTURB; > perl constant.pl leave me alone
  • 20. use Exporter; package MyPackage; use warnings; use strict; use Exporter qw(import); our @EXPORT_OK = qw(my_subroutine); sub my_subroutine { print quot;hellonquot;; } 1;
  • 21. use Exporter; use warnings; use strict; use MyPackage qw(my_subroutine); my_subroutine();
  • 23. use Data::Dumper; use warnings; use strict; use Data::Dumper; print Dumper @ARGV; > perl datadumper.pl hello frozen perl $VAR1 = [ 'hello', 'frozen', 'perl' ];
  • 25. use Class::Accessor; sub name { my ($self, $value) = @_; $self->{name} = $value if $value; return $self->{name}; }
  • 26. use Class::Accessor; package MyClass; use base qw(Class::Accessor); __PACKAGE__->mk_accessors(qw(name));
  • 28. use Carp; 1 package PackageOne; 2 3 sub y { z(); } 4 sub z { die('oops'); } 5 6 package PackageTwo; $ perl die.pl 7 oops at die.pl line 4. 8 sub a { b(); } 9 sub b { PackageOne::y(); } 10 11 package main; 12 13 PackageTwo::a();
  • 29. use Carp; 1 package PackageOne; 2 3 use Carp; 4 5 sub y { z(); } 6 sub z { croak('oops'); } 7 $ perl croak.pl 8 package PackageTwo; oops at croak.pl line 11 9 10 sub a { b(); } 11 sub b { PackageOne::y(); } 12 13 package main; 14 15 PackageTwo::a();
  • 30. use Carp; 1 package PackageOne; 2 3 use Carp qw(confess); 4 $ perl confess.pl 5 sub y { z(); } oops at confess.pl line 6 6 sub z { confess('oops'); } PackageOne::z() called at 7 confess.pl line 5 PackageOne::y() called at 8 package PackageTwo; confess.pl line 11 9 PackageTwo::b() called at 10 sub a { b(); } confess.pl line 10 11 sub b { PackageOne::y(); } PackageTwo::a() called at 12 confess.pl line 15 13 package main; 14 15 PackageTwo::a();
  • 31. use Carp; caller’s standard full stacktrace perspective warn carp cluck die croak confess
  • 33. use Carp::Assert; use Carp::Assert; assert( 1 > 0 ); affirm { my $name = 'Josh'; my @attendees = qw( Josh Heather Addy ); grep { $_ eq $name } @attendees; } > perl assert.pl
  • 34. use Carp::Assert; use Carp::Assert; assert( 1 > 2); affirm { my $name = 'Josh'; my @attendees = qw( Josh Heather Addy ); grep { $_ eq $name } @attendees; } > perl assert.pl Assertion failed! at /opt/local/lib/perl5/site_perl/5.8.8/Carp/Assert.pm line 281 Carp::Assert::assert('') called at assert.pl line 5
  • 35. use Carp::Assert; use Carp::Assert; assert( 1 > 0); affirm { my $name = 'Joshua'; my @attendees = qw( Josh Heather Addy ); grep { $_ eq $name } @attendees; } > perl assert.pl Assertion ({ use warnings; use strict 'refs'; my $name = 'Joshua'; my(@attendees) = ('Josh', 'Heather', 'Addy'); grep {$_ eq $name;} @attendees; }) failed! at /opt/local/lib/perl5/site_perl/5.8.8/Carp/Assert.pm line 340 Carp::Assert::affirm('CODE(0x1800ee0)') called at assert.pl line 11
  • 37. use File::Spec; use warnings; use strict; use File::Spec; my @dirs = File::Spec->splitdir($0); print '[', join('][', @dirs), quot;]nquot;; my $dir = File::Spec->join(@dirs); print $dir, quot;nquot;; > perl /Users/joshua/examples/filespec.pl [][Users][joshua][examples][filespec.pl] /Users/joshua/examples/filespec.pl
  • 40. use File::stat; use warnings; use strict; use File::stat; my $s = stat($0); print $s->size, quot;nquot;; > perl filestat.pl 84
  • 42. use File::Slurp; { local(*INPUT, $/); open (INPUT, $file) || die quot;can't open $file: $!quot;; $var = <INPUT>; }
  • 43. use File::Slurp; my $text = read_file( $file ); my @lines = read_file( $file );
  • 46. use File::Copy; use warnings; use strict; use File::Copy; my $command = quot;cp $0 $0.bkupquot;; `$command`;
  • 47. use File::Copy; use warnings; use strict; use File::Copy; copy $0, $0 . '.bkup' or die $!;
  • 49. use File::Temp; use warnings; use strict; use File::Temp; my $fh = File::Temp->new( UNLINK => 1 ); print $fh->filename, quot;nquot;; > perl tempfile.pl /tmp/yZin81tl6z
  • 50. use File::Temp; use warnings; use strict; use File::Temp; my $fh = File::Temp->newdir( CLEANUP => 1 ); print $fh->dirname, quot;nquot;; > perl tempdir.pl /tmp/HggvehyAyw
  • 52. use File::Find; use warnings; use strict; use File::Find; find( sub { print quot;$File::Find::namenquot; }, '/Users/joshua/' ); > perl filefind.pl /Users/joshua/...
  • 54. use File::Next; use warnings; use strict; use File::Next; my $files = File::Next::files( '/Users/joshua/' ); while ( defined ( my $file = $files->() ) ) { print quot;$filenquot;; } > perl filenext.pl /Users/joshua/...
  • 56. use File::Basename; use warnings; use strict; use File::Basename; my $file = basename $0; my $path = dirname $0; my ($file2, $path2) = fileparse $0; print join(quot;nquot;, $file, $path, $file2, $path2), quot;nquot;; > perl /Users/joshua/examples/basename.pl basename.pl /Users/joshua/examples basename.pl /Users/joshua/examples/
  • 58. use File::HomeDir; use warnings; use strict; use File::HomeDir; print File::HomeDir->my_home(), quot;nquot;; print File::HomeDir->my_data(), quot;nquot;; > perl filehomedir.pl /Users/joshua /Users/joshua/Library/Application Support
  • 60. use IO::File; use warnings; use strict; my $fh; open( $fh, '<', $0 ) or die $!; print while(<$fh>); close $fh;
  • 61. use IO::File; use warnings; use strict; use IO::File; my $fh = IO::File->new( $0, 'r' ); print while(<$fh>); $fh->close;
  • 63. use FindBin; package MyModule; use warnings; use strict; sub hello { print quot;hellonquot;; } 1;
  • 64. use FindBin; use warnings; use strict; use lib 'mylib'; use MyModule; MyModule::hello(); > perl findbin.pl hello
  • 65. use FindBin; > perl ~/bin/findbin.pl Can't locate MyModule.pm in @INC (@INC contains: mylib / opt/local/lib/perl5/5.8.8/darwin-2level /opt/local/lib/ perl5/5.8.8 /opt/local/lib/perl5/site_perl/5.8.8/ darwin-2level /opt/local/lib/perl5/site_perl/5.8.8 /opt/ local/lib/perl5/site_perl /opt/local/lib/perl5/ vendor_perl/5.8.8/darwin-2level /opt/local/lib/perl5/ vendor_perl/5.8.8 /opt/local/lib/perl5/vendor_perl .) at Utility Modules That You Should Know About/findbin.pl line 4. BEGIN failed--compilation aborted at Utility Modules That You Should Know About/findbin.pl line 4.
  • 66. use FindBin; use warnings; use strict; use FindBin; use lib quot;$FindBin::Bin/../mylibquot;; use MyModule; MyModule::hello();
  • 68. use Getopt::Long; use Getopt::Long; GetOptions( 'greeting=s', 'person=s', 'prefix:s' ) or die('error'); print join( q[ ], $opt_greeting, ($opt_prefix || q[]), $opt_person), quot;nquot;; > perl getopt1.pl --greeting=hello --person=josh --prefix= hello josh
  • 69. use Getopt::Long; use warnings; use strict; use Getopt::Long; my ($greeting, $person, $prefix); GetOptions( 'greeting=s' => $greeting, 'person=s' => $person, 'prefix:s' => $prefix, ) or die('error'); print join( q[ ], $greeting, ($prefix || q[]), $person), quot;nquot;;
  • 70. use Getopt::Long; use warnings; use strict; use Getopt::Long; my %options; GetOptions( %options, 'greeting=s', 'person=s', 'prefix:s', ) or die('error'); print join( q[ ], @options{ qw(greeting prefix person) } ), quot;nquot;;
  • 72. use Pod::Usage; use Getopt::Long; use Pod::Usage; GetOptions('help', 'man') or pod2usage(2); pod2usage(1) if $opt_help; pod2usage(-verbose => 2) if $opt_man; __END__
  • 73. use Pod::Usage; =head1 NAME sample - Using GetOpt::Long and Pod::Usage =head1 SYNOPSIS sample [options] Options: -help brief help message -man full documentation =head1 OPTIONS =over 8 =item B<-help> Print a brief help message and exits. =item B<-man> Prints the manual page and exits. =back =head1 DESCRIPTION Sample is exactly that, a sample. =cut
  • 74. use Pod::Usage; > perl pod_usage.pl -h Usage: pod_usage [options] Options: -help brief help message -man full documentation Options: -help Print a brief help message and exits. -man Prints the manual page and exits.
  • 75. use Pod::Usage; > perl pod_usage.pl -m POD_USAGE(1) User Contributed Perl Documentation POD_USAGE(1) NAME pod_usage - Using GetOpt::Long and Pod::Usage SYNOPSIS pod_usage [options] Options: -help brief help message -man full documentation OPTIONS -help Print a brief help message and exits. -man Prints the manual page and exits. DESCRIPTION pod_usage just an example. perl v5.8.8 2008-02-16 POD_USAGE(1)