SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler offline
Command-line Perl




         Command-line Perl
         (Part 1)

         or: Perl one-liners saved my career

         or: `perldoc perlrun` brought to life




         Perl code on the command line
         Look Ma, no script!
         _
         $ perl print

         # Can't open perl script quot;printquot;: No such file or directory


         -e (The `e` is for hysterical raisins)
         _
         $ perl -e print

         # (No output)



         Quoting on the command line
         ...and you can quote me on that
         _
         $ perl -e ' print quot;Hellonquot;; '      # Unix


         $ perl -e quot; print 'Hello' . $/; quot;   # Win32


         $ perl -e quot; print qq'Hellon'; quot;     # Win32; sick



1 of 4
Command-line Perl




         $ perl -e quot; print qq{Hellon}; quot;       # Win32; better



         Automatic end-of-line handling
         # Calculator

         $ perl -e ' print 42 * 42 '
         1764$ perl -e ' print 42 * 42 * 42 '
         74088$


         The -l flag adds quot;nquot; to `print`
         $ perl -le ' print 42 * 42 '
         1764

         $ perl -le ' print 42 * 42 * 42 '
         74088



         Defaults
         @ARGV is the array of command-line arguments
         shift takes @ARGV as its default
         _
         $ perl -le ' print @ARGV; $z=shift; print $z; ' foo bar baz
         # foobarbaz
         # foo


         print takes $_ as default, and for sets $_ as default.
         _
         $ perl -le ' print for @ARGV ' foo bar baz
         # foo
         # bar
         # baz


2 of 4
Command-line Perl




         Warnings
         Double your money!
         $ perl -l -e ' $zz = shift; print $z . $z ' 15
         # (No output)


         Always pay for the cheap insurance
         $ perl -wle ' $zz = shift; print $z . $z ' 15
         # Name quot;main::zzquot; used only once: possible typo at -e line 1.
         # Use of uninitialized value in concatenation (.) or string at -e line 1.
         # Use of uninitialized value in concatenation (.) or string at -e line 1.


         Corrected
         $ perl -wle ' $z = shift; print $z . $z ' 15
         # 1515



         Command-line Modules
         -M means `use`
         _
         $ perl -MData::Dumper -wle 1
         # (No output)

         $ perl -MData::Dumper::Dear::John -wle 1
         # Can't locate Data/Dumper/Dear/John.pm in @INC (@INC contains ...


         $FOO::VERSION is a CPAN standard
         _
         $ perl -MData::Dumper -wle 'print $Data::Dumper::VERSION'
         # 2.121_02


3 of 4
Command-line Perl




         Advanced preview
         $ head -4 ~/Perl/Parrot/parrot_root_svn_q_log.txt
         # ------------------------------------------------------------------------
         # r38247 | chromatic | 2009-04-21 14:07:13 -0500 (Tue, 21 Apr 2009)
         # ------------------------------------------------------------------------
         # r38246 | fperrad | 2009-04-21 13:17:20 -0500 (Tue, 21 Apr 2009)

         $ cut -s -d ' ' -f 3 ~/Perl/Parrot/parrot_root_svn_q_log.txt 
            | tr quot;[:upper:]quot; quot;[:lower:]quot; | sort | uniq -c | sort -nr

         $ perl -wlane
            $h{lc $F[2]}++ if @F>1; END{ printf quot;%7dt%snquot;, $h{$_}, $_
             for sort { $h{$b} <=> $h{$a}} keys %h}
              ~/Perl/Parrot/parrot_root_svn_q_log.txt
         # 4215 leo
         # 2933 coke
         # 2850 bernhard




4 of 4

Mais conteúdo relacionado

Destaque

Aws S3 uploading tricks 2016
Aws S3 uploading tricks 2016Aws S3 uploading tricks 2016
Aws S3 uploading tricks 2016Bogdan Naydenov
 
Perl Intro 8 File Handles
Perl Intro 8 File HandlesPerl Intro 8 File Handles
Perl Intro 8 File HandlesShaun Griffith
 
Yapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlYapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlBruce Gray
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utilityNirajan Pant
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2Kazuho Oku
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processingAnton Arhipov
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with PerlKazuho Oku
 
Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testingGaruda Trainings
 
Linux Command Suumary
Linux Command SuumaryLinux Command Suumary
Linux Command Suumarymentorsnet
 
Linux command ppt
Linux command pptLinux command ppt
Linux command pptkalyanineve
 

Destaque (16)

Aws S3 uploading tricks 2016
Aws S3 uploading tricks 2016Aws S3 uploading tricks 2016
Aws S3 uploading tricks 2016
 
Perl Intro 8 File Handles
Perl Intro 8 File HandlesPerl Intro 8 File Handles
Perl Intro 8 File Handles
 
Yapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line PerlYapc::NA::2009 - Command Line Perl
Yapc::NA::2009 - Command Line Perl
 
Know the UNIX Commands
Know the UNIX CommandsKnow the UNIX Commands
Know the UNIX Commands
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2
 
Basics of unix
Basics of unixBasics of unix
Basics of unix
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processing
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editors
 
Vi editor in linux
Vi editor in linuxVi editor in linux
Vi editor in linux
 
The "vi" Text Editor
The "vi" Text EditorThe "vi" Text Editor
The "vi" Text Editor
 
Unix commands in etl testing
Unix commands in etl testingUnix commands in etl testing
Unix commands in etl testing
 
Linux Command Suumary
Linux Command SuumaryLinux Command Suumary
Linux Command Suumary
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
 

Último

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
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, ...apidays
 
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.pdfsudhanshuwaghmare1
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
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 Takeoffsammart93
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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 DiscoveryTrustArc
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
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 2024The Digital Insurer
 

Último (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
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, ...
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
+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...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation 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
 

Command Line Perl 20090423

  • 1. Command-line Perl Command-line Perl (Part 1) or: Perl one-liners saved my career or: `perldoc perlrun` brought to life Perl code on the command line Look Ma, no script! _ $ perl print # Can't open perl script quot;printquot;: No such file or directory -e (The `e` is for hysterical raisins) _ $ perl -e print # (No output) Quoting on the command line ...and you can quote me on that _ $ perl -e ' print quot;Hellonquot;; ' # Unix $ perl -e quot; print 'Hello' . $/; quot; # Win32 $ perl -e quot; print qq'Hellon'; quot; # Win32; sick 1 of 4
  • 2. Command-line Perl $ perl -e quot; print qq{Hellon}; quot; # Win32; better Automatic end-of-line handling # Calculator $ perl -e ' print 42 * 42 ' 1764$ perl -e ' print 42 * 42 * 42 ' 74088$ The -l flag adds quot;nquot; to `print` $ perl -le ' print 42 * 42 ' 1764 $ perl -le ' print 42 * 42 * 42 ' 74088 Defaults @ARGV is the array of command-line arguments shift takes @ARGV as its default _ $ perl -le ' print @ARGV; $z=shift; print $z; ' foo bar baz # foobarbaz # foo print takes $_ as default, and for sets $_ as default. _ $ perl -le ' print for @ARGV ' foo bar baz # foo # bar # baz 2 of 4
  • 3. Command-line Perl Warnings Double your money! $ perl -l -e ' $zz = shift; print $z . $z ' 15 # (No output) Always pay for the cheap insurance $ perl -wle ' $zz = shift; print $z . $z ' 15 # Name quot;main::zzquot; used only once: possible typo at -e line 1. # Use of uninitialized value in concatenation (.) or string at -e line 1. # Use of uninitialized value in concatenation (.) or string at -e line 1. Corrected $ perl -wle ' $z = shift; print $z . $z ' 15 # 1515 Command-line Modules -M means `use` _ $ perl -MData::Dumper -wle 1 # (No output) $ perl -MData::Dumper::Dear::John -wle 1 # Can't locate Data/Dumper/Dear/John.pm in @INC (@INC contains ... $FOO::VERSION is a CPAN standard _ $ perl -MData::Dumper -wle 'print $Data::Dumper::VERSION' # 2.121_02 3 of 4
  • 4. Command-line Perl Advanced preview $ head -4 ~/Perl/Parrot/parrot_root_svn_q_log.txt # ------------------------------------------------------------------------ # r38247 | chromatic | 2009-04-21 14:07:13 -0500 (Tue, 21 Apr 2009) # ------------------------------------------------------------------------ # r38246 | fperrad | 2009-04-21 13:17:20 -0500 (Tue, 21 Apr 2009) $ cut -s -d ' ' -f 3 ~/Perl/Parrot/parrot_root_svn_q_log.txt | tr quot;[:upper:]quot; quot;[:lower:]quot; | sort | uniq -c | sort -nr $ perl -wlane $h{lc $F[2]}++ if @F>1; END{ printf quot;%7dt%snquot;, $h{$_}, $_ for sort { $h{$b} <=> $h{$a}} keys %h} ~/Perl/Parrot/parrot_root_svn_q_log.txt # 4215 leo # 2933 coke # 2850 bernhard 4 of 4