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

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
 

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

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Dernier (20)

Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, Ocado
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 

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