SlideShare une entreprise Scribd logo
1  sur  4
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette

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
 

En vedette (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
 

Dernier

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
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
 
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 educationjfdjdjcjdnsjd
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Dernier (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

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