SlideShare une entreprise Scribd logo
1  sur  24
Perl5i Marcos Rebelo (oleber@gmail.com)
Tribal knowledge
use v5.10; use strict; use warnings; use File::Find; use File::Glob 'bsd_glob'; use DateTime; my ( $from, $to ) = @ARGV; die "Directory $from not found" if not -d $from; die "Directory $to not found"  if not -d $to; sub epoch_to_iso8601 { my ( $time ) = @_; return DateTime->from_epoch(epoch => $time)->iso8601; } File::Find::find(  { wanted => amp;process_file, no_chdir => 1 },  $from );
sub process_file { my $log_prefix = epoch_to_iso8601(time); my $file_name = $File::Find::name; my $postfix = File::Spec->abs2rel( $file_name, $from ); my $destiny = File::Spec->join( $to, $postfix ); die "$file_name isn't readable"  if not -r $file_name; if ( -d $file_name ) { return if -d $destiny; mkdir($destiny) or die "Can't mkdir $destiny: $!"; say "$log_prefix: Directory $destiny created"; } else { ...
... } else { my $original_utime = ( stat $file_name )[9]; if ( my @files = bsd_glob(&quot;$destiny.BACKUP.*&quot;) ) { my $last_path = ( sort @files )[-1]; return if $original_utime < ( stat $last_path )[9]; } $destiny = &quot;$destiny.BACKUP.&quot;  . epoch_to_iso8601($original_utime); system( 'cp', $file_name, $destiny ) and die &quot;Can't cp $file_name $destiny&quot;; say &quot;$log_prefix: cp $file_name $destiny&quot;; } }
Modern::Perl use v5.10; use strict; use warnings; To use perl5i::2;
autodie mkdir($destiny)  or die &quot;Can't mkdir $destiny: $!&quot; ; To mkdir($destiny); Error Example: Can't mkdir('backup/pippo'): Permission denied at perl5i/example.pl line 26
autodie system('cp', $file_name, $destiny) and die &quot;Can't cp $file_name $destiny&quot; ; To system('cp', $file_name, $destiny); Error example: &quot;cp&quot; unexpectedly returned exit value 1 at (eval 67) line 13 at perl5i/example.pl line 37
time  to Object my $log_time_prefix = epoch_to_iso8601(time()) ; To my $log_time_prefix =  time()->iso8601 ;
stat  to Object my $original_utime =  ( stat($file_name) )[9] ; To my $original_utime =  stat($file_name)->mtime ;
stat  to Object return if $original_utime <  ( stat($last_path) )[9] ; To return if $original_utime <  stat($last_path)->mtime ;
function/method signature sub epoch_to_iso8601 { my ( $time ) = @_; To func epoch_to_iso8601( $time ) {
autobox my $last_path =  ( sort @existing_files )[-1] ; To my $last_path =  @existing_files->maxstr ;
Extend Scalars  func epoch_to_iso8601($time) { ... epoch_to_iso8601($original_utime); To func SCALAR::epoch_to_iso8601($time) { ... $original_utime->epoch_to_iso8601;
use v5.10; use strict; use warnings; use File::Find; use File::Glob 'bsd_glob'; use DateTime; my ( $from, $to ) = @ARGV; die &quot;Directory $from not found&quot; if not -d $from; die &quot;Directory $to not found&quot;  if not -d $to; sub epoch_to_iso8601 { my ( $time ) = @_; return DateTime->from_epoch(epoch => $time)->iso8601; } File::Find::find(  { wanted => amp;process_file, no_chdir => 1 },  $from );
use perl5i::2; use File::Find; use File::Glob 'bsd_glob'; use DateTime; my ( $from, $to ) = @ARGV; die &quot;Directory $from not found&quot; if !-d $from; die &quot;Directory $to not found&quot; if !-d $to; func SCALAR::epoch_to_iso8601( $time )  {  DateTime->from_epoch(epoch => $time)->iso8601  } File::Find::find(  { wanted => amp;process_file, no_chdir => 1 },  $from );
sub process_file { my $log_prefix =  epoch_to_iso8601(time()); my $file_name = $File::Find::name; my $postfix = File::Spec->abs2rel( $file_name, $from ); my $destiny = File::Spec->join( $to, $postfix ); die &quot;$file_name isn't readable&quot;  if not -r $file_name; if ( -d $file_name ) { return if -d $destiny; mkdir($destiny) or die &quot;Can't mkdir $destiny: $!&quot;; say &quot;$log_prefix: Directory $destiny created&quot;; } else { ...
func process_file()  { my $log_prefix =  time->iso8601 ; my $file_name = $File::Find::name; my $postfix = File::Spec->abs2rel( $file_name, $from ); my $destiny = File::Spec->join( $to, $postfix ); die &quot;$file_name isn't readable&quot; if not -r $file_name; if ( -d $file_name ) { return if -d $destiny; mkdir($destiny); say &quot;$log_prefix: Directory $destiny created&quot;; } else { ...
... } else { my $original_utime =  ( stat $file_name )[9] ; if ( my @files = bsd_glob(&quot;$destiny.BACKUP.*&quot;) ) { my $last_path = ( sort @files )[-1]; return if $original_utime <  ( stat $last_path )[9] ; } $destiny = &quot;$destiny.BACKUP.&quot;  .  epoch_to_iso8601($original_utime) ; system( 'cp', $file_name, $destiny ) and die &quot;Can't cp $file_name $destiny&quot;; say &quot;$log_prefix: cp $file_name $destiny&quot;; } }
... } else { my $original_utime =  stat($file_name)->mtime ; if ( my @files = bsd_glob(&quot;$destiny.BACKUP.*&quot;) ) { return if $original_utime <  stat( @files->maxstr )->mtime ; } $destiny = &quot;$destiny.BACKUP.&quot; .  $original_utime->epoch_to_iso8601 ; system( 'cp', $file_name, $destiny ); say &quot;$log_prefix: cp $file_name $destiny&quot;; } }
Other features
Meta Object # the object's class my $class = $obj->mo->class; # its parent classes my @isa = $obj->mo->isa; # the complete inheritance hierarchy my @complete_isa = $obj->mo->linear_isa; # the reference type of the object my $reftype = $obj->mo->reftype;
Packages ,[object Object]
use English qw( -no_match_vars );

Contenu connexe

Tendances

News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101hendrikvb
 
YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYusuke Wada
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravelRazvan Raducanu, PhD
 
Undercover Pods / WP Functions
Undercover Pods / WP FunctionsUndercover Pods / WP Functions
Undercover Pods / WP Functionspodsframework
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
 
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
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON APIpodsframework
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門Yusuke Wada
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP GeneratorsMark Baker
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Arc & Codementor
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsMark Baker
 

Tendances (20)

News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
16.mysql stored procedures in laravel
16.mysql stored procedures in laravel16.mysql stored procedures in laravel
16.mysql stored procedures in laravel
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3
 
Undercover Pods / WP Functions
Undercover Pods / WP FunctionsUndercover Pods / WP Functions
Undercover Pods / WP Functions
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
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
 
Introduction to the Pods JSON API
Introduction to the Pods JSON APIIntroduction to the Pods JSON API
Introduction to the Pods JSON API
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
 
Electrify your code with PHP Generators
Electrify your code with PHP GeneratorsElectrify your code with PHP Generators
Electrify your code with PHP Generators
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
My shell
My shellMy shell
My shell
 
Tax management-system
Tax management-systemTax management-system
Tax management-system
 
Looping the Loop with SPL Iterators
Looping the Loop with SPL IteratorsLooping the Loop with SPL Iterators
Looping the Loop with SPL Iterators
 

En vedette

Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Dotan Dimet
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tCosimo Streppone
 

En vedette (6)

Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
Modern Perl
Modern  PerlModern  Perl
Modern Perl
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Mojolicious and REST
Mojolicious and RESTMojolicious and REST
Mojolicious and REST
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 

Similaire à Perl5i

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 mongersbrian d foy
 
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
 
Drupal Lightning FAPI Jumpstart
Drupal Lightning FAPI JumpstartDrupal Lightning FAPI Jumpstart
Drupal Lightning FAPI Jumpstartguestfd47e4c7
 
Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal coredrumm
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
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
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationAttila Balazs
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic trapsDamien Seguy
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applicationsJoe Jiang
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With PhpJeremy Coates
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To MocoNaoya Ito
 
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 testsFrank Kleine
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたTakeshi Arabiki
 

Similaire à Perl5i (20)

spug_2008-08
spug_2008-08spug_2008-08
spug_2008-08
 
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
 
wget.pl
wget.plwget.pl
wget.pl
 
Ae internals
Ae internalsAe internals
Ae internals
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
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)
 
Drupal Lightning FAPI Jumpstart
Drupal Lightning FAPI JumpstartDrupal Lightning FAPI Jumpstart
Drupal Lightning FAPI Jumpstart
 
Maintaining your own branch of Drupal core
Maintaining your own branch of Drupal coreMaintaining your own branch of Drupal core
Maintaining your own branch of Drupal core
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Barely Legal Xxx Perl Presentation
Barely Legal Xxx Perl PresentationBarely Legal Xxx Perl Presentation
Barely Legal Xxx Perl Presentation
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Exploiting Php With Php
Exploiting Php With PhpExploiting Php With Php
Exploiting Php With Php
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
 
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
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 

Dernier

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[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.pdfhans926745
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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 MenDelhi Call girls
 
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 MenDelhi Call girls
 
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...Enterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
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.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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 Nanonetsnaman860154
 

Dernier (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
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
 
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...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 

Perl5i

  • 1. Perl5i Marcos Rebelo (oleber@gmail.com)
  • 3. use v5.10; use strict; use warnings; use File::Find; use File::Glob 'bsd_glob'; use DateTime; my ( $from, $to ) = @ARGV; die &quot;Directory $from not found&quot; if not -d $from; die &quot;Directory $to not found&quot; if not -d $to; sub epoch_to_iso8601 { my ( $time ) = @_; return DateTime->from_epoch(epoch => $time)->iso8601; } File::Find::find( { wanted => amp;process_file, no_chdir => 1 }, $from );
  • 4. sub process_file { my $log_prefix = epoch_to_iso8601(time); my $file_name = $File::Find::name; my $postfix = File::Spec->abs2rel( $file_name, $from ); my $destiny = File::Spec->join( $to, $postfix ); die &quot;$file_name isn't readable&quot; if not -r $file_name; if ( -d $file_name ) { return if -d $destiny; mkdir($destiny) or die &quot;Can't mkdir $destiny: $!&quot;; say &quot;$log_prefix: Directory $destiny created&quot;; } else { ...
  • 5. ... } else { my $original_utime = ( stat $file_name )[9]; if ( my @files = bsd_glob(&quot;$destiny.BACKUP.*&quot;) ) { my $last_path = ( sort @files )[-1]; return if $original_utime < ( stat $last_path )[9]; } $destiny = &quot;$destiny.BACKUP.&quot; . epoch_to_iso8601($original_utime); system( 'cp', $file_name, $destiny ) and die &quot;Can't cp $file_name $destiny&quot;; say &quot;$log_prefix: cp $file_name $destiny&quot;; } }
  • 6. Modern::Perl use v5.10; use strict; use warnings; To use perl5i::2;
  • 7. autodie mkdir($destiny) or die &quot;Can't mkdir $destiny: $!&quot; ; To mkdir($destiny); Error Example: Can't mkdir('backup/pippo'): Permission denied at perl5i/example.pl line 26
  • 8. autodie system('cp', $file_name, $destiny) and die &quot;Can't cp $file_name $destiny&quot; ; To system('cp', $file_name, $destiny); Error example: &quot;cp&quot; unexpectedly returned exit value 1 at (eval 67) line 13 at perl5i/example.pl line 37
  • 9. time to Object my $log_time_prefix = epoch_to_iso8601(time()) ; To my $log_time_prefix = time()->iso8601 ;
  • 10. stat to Object my $original_utime = ( stat($file_name) )[9] ; To my $original_utime = stat($file_name)->mtime ;
  • 11. stat to Object return if $original_utime < ( stat($last_path) )[9] ; To return if $original_utime < stat($last_path)->mtime ;
  • 12. function/method signature sub epoch_to_iso8601 { my ( $time ) = @_; To func epoch_to_iso8601( $time ) {
  • 13. autobox my $last_path = ( sort @existing_files )[-1] ; To my $last_path = @existing_files->maxstr ;
  • 14. Extend Scalars func epoch_to_iso8601($time) { ... epoch_to_iso8601($original_utime); To func SCALAR::epoch_to_iso8601($time) { ... $original_utime->epoch_to_iso8601;
  • 15. use v5.10; use strict; use warnings; use File::Find; use File::Glob 'bsd_glob'; use DateTime; my ( $from, $to ) = @ARGV; die &quot;Directory $from not found&quot; if not -d $from; die &quot;Directory $to not found&quot; if not -d $to; sub epoch_to_iso8601 { my ( $time ) = @_; return DateTime->from_epoch(epoch => $time)->iso8601; } File::Find::find( { wanted => amp;process_file, no_chdir => 1 }, $from );
  • 16. use perl5i::2; use File::Find; use File::Glob 'bsd_glob'; use DateTime; my ( $from, $to ) = @ARGV; die &quot;Directory $from not found&quot; if !-d $from; die &quot;Directory $to not found&quot; if !-d $to; func SCALAR::epoch_to_iso8601( $time ) { DateTime->from_epoch(epoch => $time)->iso8601 } File::Find::find( { wanted => amp;process_file, no_chdir => 1 }, $from );
  • 17. sub process_file { my $log_prefix = epoch_to_iso8601(time()); my $file_name = $File::Find::name; my $postfix = File::Spec->abs2rel( $file_name, $from ); my $destiny = File::Spec->join( $to, $postfix ); die &quot;$file_name isn't readable&quot; if not -r $file_name; if ( -d $file_name ) { return if -d $destiny; mkdir($destiny) or die &quot;Can't mkdir $destiny: $!&quot;; say &quot;$log_prefix: Directory $destiny created&quot;; } else { ...
  • 18. func process_file() { my $log_prefix = time->iso8601 ; my $file_name = $File::Find::name; my $postfix = File::Spec->abs2rel( $file_name, $from ); my $destiny = File::Spec->join( $to, $postfix ); die &quot;$file_name isn't readable&quot; if not -r $file_name; if ( -d $file_name ) { return if -d $destiny; mkdir($destiny); say &quot;$log_prefix: Directory $destiny created&quot;; } else { ...
  • 19. ... } else { my $original_utime = ( stat $file_name )[9] ; if ( my @files = bsd_glob(&quot;$destiny.BACKUP.*&quot;) ) { my $last_path = ( sort @files )[-1]; return if $original_utime < ( stat $last_path )[9] ; } $destiny = &quot;$destiny.BACKUP.&quot; . epoch_to_iso8601($original_utime) ; system( 'cp', $file_name, $destiny ) and die &quot;Can't cp $file_name $destiny&quot;; say &quot;$log_prefix: cp $file_name $destiny&quot;; } }
  • 20. ... } else { my $original_utime = stat($file_name)->mtime ; if ( my @files = bsd_glob(&quot;$destiny.BACKUP.*&quot;) ) { return if $original_utime < stat( @files->maxstr )->mtime ; } $destiny = &quot;$destiny.BACKUP.&quot; . $original_utime->epoch_to_iso8601 ; system( 'cp', $file_name, $destiny ); say &quot;$log_prefix: cp $file_name $destiny&quot;; } }
  • 22. Meta Object # the object's class my $class = $obj->mo->class; # its parent classes my @isa = $obj->mo->isa; # the complete inheritance hierarchy my @complete_isa = $obj->mo->linear_isa; # the reference type of the object my $reftype = $obj->mo->reftype;
  • 23.
  • 24. use English qw( -no_match_vars );
  • 25. use File::chdir; # gives you $CWD # representing the current working # directory
  • 26. use Time::y2038; # gmtime() and # localtime() will now safely work with # dates beyond the year 2038 and before # 1901.
  • 29. Q / A