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

Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Patrick Viafore
 
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 PlanningIES VE
 
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, OcadoUXDXConf
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsStefano
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsUXDXConf
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKUXDXConf
 
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áCzechDreamin
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCzechDreamin
 
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...FIDO Alliance
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...FIDO Alliance
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FIDO Alliance
 
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 DiehlPeter Udo Diehl
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 

Último (20)

Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
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
 
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
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
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á
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
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...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
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
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 

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