SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
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

Más contenido relacionado

Destacado

Perl Intro 8 File Handles
Perl Intro 8 File HandlesPerl Intro 8 File Handles
Perl Intro 8 File Handles
Shaun Griffith
 
Practical unix utilities for text processing
Practical unix utilities for text processingPractical unix utilities for text processing
Practical unix utilities for text processing
Anton Arhipov
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
Kazuho Oku
 

Destacado (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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

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