SlideShare uma empresa Scribd logo
1 de 15
Baixar para ler offline
PATH::TINY 
Chiba.pm #5 / @waniji
ß…Ãu 
@waniji 
´–Ï´£È§ò·Ê¡ 
VimsPerl„PrŠe
PATH::TINYt{ 
Ô £êìfá·ä–ê 
Path::ClasszTinyh 
File::Spec, File::Copy, File::Temp, File::Path, File::statvuž 
žoríR{vX|_zá·ä–ê1pslPkPca 
Še 
David Golden·XAuthor
_Ÿv_tXcaŠe 
my $file = path("/home/waniji/memo.txt"); 
# ファイル名のみ表示 
say $file->basename; 
# ファイルに書き込み 
my $fh = $file->openw; 
$fh->print("chiba.pm") 
# ファイルの内容をすべて読み込み 
my $data = $file->slurp; 
# ファイルを削除 
$file->remove; 
# 一時ファイルを作成 
my $temp = Path::Tiny->tempfile;
Æ¢ë®ÇéAzÔ £êDžª¥òÇ 
my $file = path(/home/waniji/); 
my $iterator = $file-iterator( { recurse = 1 } ); 
while( my $object = $iterator-() ) { 
$count++ if $object-is_file; 
}
Po}P/^•˜— 
# /home/waniji/chibapm/memo.txt に aaa という文字列を書き込み 
my $file = path(/home/waniji/memo.txt); 
$file-parent-child(chibapm, memo.txt)-touchpath-openw-print(aaa);
PATH::CLASStzঠ
ŸaP 
íP 
1Ô £ê 
UTF-8Jzà¼ÂÈXJa˜rP— 
Unix or Windows z‹”f;Ë
ØòÀÝ–®(Ô £êw„YŸsg) 
my $path = /home/waniji/hoge.txt; 
cmpthese( 10000, { 
'Path::Tiny' = sub { 
my $file = path($path); 
$file-openw-print(aaa); 
$file-remove; 
}, 
'Path::Class' = sub { 
my $file = file($path); 
$file-openw-print(aaa); 
$file-remove; 
}, 
}); 
Rate Path::Class Path::Tiny 
Path::Class 1862/s -- -29% 
Path::Tiny 2632/s 41% --
ØòÀÝ–®(Æ¢ë®ÇéAzÔ £êžª¥òÇ) 
my $path = /home/waniji/temp; 
cmpthese( 100, { 
'Path::Tiny' = sub { 
my $dir = path($path); 
my $iterator = $dir-iterator( { recurse = 1 } ); 
my $count; 
while( my $object = $iterator-() ) { 
$count++ if $object-is_file; 
} 
}, 
'Path::Class' = sub { 
my $dir = dir($path); 
my $count; 
$dir-recurse( callback = sub { 
my $object = shift; 
$count++ if -f $object; 
}); 
}, 
}); Rate Path::Class Path::Tiny 
Path::Class 10.7/s -- -67% 
Path::Tiny 32.1/s 200% --
UTF-8zÔ £êžopencr‹— 
# Path::Class 
my $fh = $file-open(':encoding(UTF-8)') or die can't open $file: $!; 
# Path::Tiny 
my $fh = $file-openr_utf8;
PATH::TINYsÎÝok_t
ì–ªêW•NFSwÔ £êž¤” 
my $file = path(/home/waniji/memo.txt); 
$file-move(/nfs/memo.txt); 
ŒŒ 
¾{±¿z¶{½ 
‹Y^Y^Y^Y^Y‹
Path::Tinyzmove{ÆósrenamežžJcrP—k| £v 
—Ô £ê¶¸Åßw¤”e—_t{cavP} 
sub move { 
my ( $self, $dst ) = @_; 
return rename( $self-[PATH], $dst ) 
|| $self-_throw( 'rename', $self-[PATH] . ' - '$dst' ); 
}
PCŽ 
use File::Copy 'move'; 
move $file, /nfs/memo.txt;
Št 
6q

Mais conteúdo relacionado

Mais procurados

Plone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxPlone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope Rpx
Paris, France
 
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
Ben Pope
 
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Hiroshi Shibamura
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 
Threading
ThreadingThreading
Threading
b290572
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
Yusuke Wada
 

Mais procurados (20)

File system
File systemFile system
File system
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
 
Plone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxPlone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope Rpx
 
Puppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future PastPuppet Camp Amsterdam 2015: Manifests of Future Past
Puppet Camp Amsterdam 2015: Manifests of Future Past
 
Not Really PHP by the book
Not Really PHP by the bookNot Really PHP by the book
Not Really PHP by the book
 
Perl5i
Perl5iPerl5i
Perl5i
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
 
TDC São Paulo 2016 - Become a jedi with php streams
TDC São Paulo 2016 - Become a jedi with php streamsTDC São Paulo 2016 - Become a jedi with php streams
TDC São Paulo 2016 - Become a jedi with php streams
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
 
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
 
scdevsumit 2016 - Become a jedi with php streams
scdevsumit 2016 - Become a jedi with php streamsscdevsumit 2016 - Become a jedi with php streams
scdevsumit 2016 - Become a jedi with php streams
 
Laporan setting dns
Laporan setting dnsLaporan setting dns
Laporan setting dns
 
Important info
Important infoImportant info
Important info
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Php i basic chapter 4
Php i basic chapter 4Php i basic chapter 4
Php i basic chapter 4
 
PHP pod mikroskopom
PHP pod mikroskopomPHP pod mikroskopom
PHP pod mikroskopom
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Linux Shell Scripts and Shell Commands✌️
Linux Shell Scripts and Shell Commands✌️Linux Shell Scripts and Shell Commands✌️
Linux Shell Scripts and Shell Commands✌️
 
Threading
ThreadingThreading
Threading
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
 

Semelhante a Path::Tiny

On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
Positive Hack Days
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
unodelostrece
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
clkao
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
lestrrat
 

Semelhante a Path::Tiny (20)

spug_2008-08
spug_2008-08spug_2008-08
spug_2008-08
 
wget.pl
wget.plwget.pl
wget.pl
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
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
 
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
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
 
Perl Programming - 03 Programming File
Perl Programming - 03 Programming FilePerl Programming - 03 Programming File
Perl Programming - 03 Programming File
 
Perl basics for Pentesters
Perl basics for PentestersPerl basics for Pentesters
Perl basics for Pentesters
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Php
PhpPhp
Php
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
 
WordPress 運用を支える Perl
WordPress 運用を支える PerlWordPress 運用を支える Perl
WordPress 運用を支える Perl
 
My shell
My shellMy shell
My shell
 
Utility Modules That You Should Know About
Utility Modules That You Should Know AboutUtility Modules That You Should Know About
Utility Modules That You Should Know About
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門Kansai.pm 10周年記念 Plack/PSGI 入門
Kansai.pm 10周年記念 Plack/PSGI 入門
 
Why Hacking WordPress Search Isn't Some Big Scary Thing
Why Hacking WordPress Search Isn't Some Big Scary ThingWhy Hacking WordPress Search Isn't Some Big Scary Thing
Why Hacking WordPress Search Isn't Some Big Scary Thing
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Path::Tiny