SlideShare ist ein Scribd-Unternehmen logo
1 von 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 );

Weitere ähnliche Inhalte

Was ist angesagt?

News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
Fabien Potencier
 
YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
Yusuke Wada
 
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
Tatsuhiko Miyagawa
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
Yusuke Wada
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie Perl5i

Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri 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 Presentation
Attila Balazs
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
Joe Jiang
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Introduction To Moco
Introduction To MocoIntroduction To Moco
Introduction To Moco
Naoya Ito
 

Ähnlich wie 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を作ってみた
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

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