SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
3.
Contents
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
4.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
51.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
62.
# overrides various built-ins...
use autodie;
# Now, they all succeed or die!
open my $foo, '>', 'file.txt';
chdir 'foo/bar';
pipe my($baz), my($buh);
readline $foo;
print “Do you ever check for print
errors???”;
63.
autodie is indispensable.
Why write an “or die” clause after
every open() when you no
longer have to???
82.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
104.
Stop messing up inheritance,
destructors, accessors and all
those little things that you have to
write over and over and over
again...
105.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
114.
use Path::Class qw(dir file);
# create dir and file objects...
my $dir = dir('foo', 'bar');
my $file = file('bob', 'file.txt');
# Stringifies with proper separator on
# each supported platform
print "dir: $dirn";
print "file: $filen";
# methods do what you expect...
my $subdir = $dir->subdir('baz');
my $parent = $subdir->parent;
my $dir2 = $file->dir;
142.
Can you remember this?
my ($dev, $ino, $mode, $nlink, $uid,
$gid, $rdev, $size, $atime, $mtime,
$ctime, $blksize, $blocks) =
stat $file;
143.
Maybe this?
my $dev = (stat $file)[0];
my $ino = (stat $file)[1];
my $mode = (stat $file)[2];
my $nlink = (stat $file)[3];
my $uid = (stat $file)[4];
my $gid = (stat $file)[5];
my $rdev = (stat $file)[6];
my $size = (stat $file)[7];
# etc...
144.
Try this, instead...
use File::stat;
my $s = stat $file;
$s->dev;
$s->ino;
$s->size;
Much nicer, no?
145.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
151.
use Hash::Merge::Simple qw(merge);
my $a = {
a => 1, c => 3,
d => { i => 2 }, r => {}
};
my $b = {
b => 2, a => 100,
d => { l => 4 }
};
my $c = merge $a, $b;
# $c is now {
# a => 100, b => 2, c => 3,
# d => { i => 2, l => 4 }, r => {} }
154.
use Params::Util qw(_SCALAR _HASH _INSTANCE);
sub foo {
my $object = _INSTANCE(shift, 'Foo') or die;
my $image = _SCALAR(shift) or die;
my $opts = _HASHLIKE(shift) || {};
}
167.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
184.
For when you're willing to be
surprised at the dates found!
185.
Simply works harder to find dates
and times in text, at the cost of
possibly false-positives.
186.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
192.
use Text::CSV;
my $csv = Text::CSV->new({ binary => 1 });
open my $fh, "<:encoding(utf8)", "test.csv";
while ( my $row = $csv->getline( $fh ) ) {
$row->[2] =~ m/pattern/ or next;
push @rows, $row;
}
199.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion
217.
Make using system() and output
capturing (a-la backticks) safer
218.
use IPC::System::Simple
qw(system systemx);
# overrides system() built-in...
# Succeed or die, avoid shell if @args
system("some_command",@args);
# NEVER invokes the shell
systemx("some_command",@args);
219.
use IPC::System::Simple
qw(capture capturex);
# Use capture() instead of backticks:
(also works in list context)
# Succeeds or dies,
# avoids shell if @args
my $output =
capture("some_command",@args);
# NEVER invokes the shell
My $output =
capturex("some_command",@args);
220.
Introduction
The Little Things
Slightly Bigger Things
Handling Files and Filesystems
Wrangling Data Structures and Types
Dealing with Dates and Times
Reading and Writing File Formats
Potpourri
Conclusion