SlideShare a Scribd company logo
1 of 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 );

More Related Content

What's hot

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
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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
 

Similar to 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
 

Similar to 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を作ってみた
 

Recently uploaded

Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseWSO2
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
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 FMESafe Software
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingWSO2
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 

Recently uploaded (20)

Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
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
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

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