SlideShare a Scribd company logo
Perl 6 Command Line Scripting
A few tips
Hi
● Simon Proctor
● Scimon most places (Twitter etc)
● Senior Developer at Zoopla
● Addicted to Perl6
Command Line Switches
● -e : Same as -E in Perl5. Strict mode on and say works.
● -n : Runs the program with $_ set to each line in the given files. Note newlines
are stripped from the input lines.
● -p : As -n then say the value of $_ (calls gist on the value and adds a newline).
● -I path : Adds the path for module searches.
● -M module : Loads the given module prior to running the script.
Not included -0, -a, -C, -d, -D, -E, -f, -F, -i, -l, -M-, -s, -S, -t, -T, -u, -U, -X
Also available PERL6LIB environment variable useful when using prove
@*ARGS and $*ARGFILES
● @*ARGS is an Array of all the arguments passed to the programme.
● All arguments are type Str but the Array itself is not typed.
● $*ARGFILES is an IO::CatHandle (actually IO::ArgFiles) object that treats
all the values in @*ARGS as paths to files and allows you to iterate over all of them.
● $*ARGFILES is lazily evaluated. It will throw an Exception if the paths do not
exist.
● $*ARGFILES is set to $*IN if there are no arguments passed.
Welcome to MAIN
multi sub MAIN( *@files ) {...}
multi sub MAIN( $file1, $file2 ) {...}
multi sub MAIN( :$s(size) ) {...}
● @*ARGS is mapped into a signature with a few things to bear in mind
○ All inputs a Str typed but if they match a numeric format they may be a subtype :
■ IntStr, RatStr, ComplexStr, NumStr all are both their appropriate types as required
● Named parameters will be either a Scalar or an Array depending on the
number of times they are called.
● Named parameters can also be stored in a slurpy hash *%args.
Auto documentation
● Default response to no matching signature is to call the USAGE sub.
● If you want to call the USAGE sub you need to provide one.
● Default is to output the $*USAGE string.
○ Created by reading documentation on all MAIN subs.
○ #| attaches before the thing being documented
○ #= attached after the thing being documented
○ Both are POD directives and will be included in the documentation
○ To discount a MAIN sub from the $*USAGE string creation give it the trait is
hidden-from-USAGE
Auto documentation : Example
multi sub MAIN( :$h? ) is hidden-from-USAGE {
USAGE();
}
multi sub MAIN( :$h!, *@ ) is hidden-from-USAGE {
USAGE();
}
#| Sum up some numbers
multi sub MAIN(
*@nums #= A list of numbers
) {
say [+] @nums;
}
sub USAGE() {
say "Highly useful summing thing";
say $*USAGE;
}
Highly useful summing thing
Usage:
doc.pl6 [<nums> ...] -- Sum up some numbers
[<nums> ...] A list of numbers
Tips and Tricks
● END and BEGIN phasers and state variables can be very useful with -n and -p
● my %*SUB-MAIN-OPTS = :named-anywhere;
○ Allows named arguments anywhere in the parsing order.
● subtype Single of Any where * !~~ Positional;
○ Use on a named parameter to ensure only one can be passed.
● Subsets::IO includes a number of useful predefined IO subsets
○ E.G. IO::Path::dw for a writable directory
● For larger scripts move the core code into a module and use you script as a
launcher

More Related Content

PPTX
Pointer to function 2
PPTX
Programming in c function
PPSX
Functions in c
PPTX
Presention programming
PPT
Functions and pointers_unit_4
PPTX
C formatted and unformatted input and output constructs
PDF
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
PPT
Function overloading(C++)
Pointer to function 2
Programming in c function
Functions in c
Presention programming
Functions and pointers_unit_4
C formatted and unformatted input and output constructs
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Function overloading(C++)

What's hot (20)

PPTX
This pointer
PPSX
C programming function
PPT
Function
PPTX
Pointers in C/C++ Programming
PPTX
CHAPTER 6
PPT
Array Presentation (EngineerBaBu.com)
PPT
CPP Language Basics - Reference
PPTX
Programming in C (part 2)
PPT
Lecture 13 - Storage Classes
PPTX
Recursion in c++
PDF
03 function overloading
PPTX
Functions
PPTX
Linq inside out
PPTX
Functions (Computer programming and utilization)
PDF
Swift 3.0 の新しい機能(のうちの9つ)
PDF
Linq & lambda overview C#.net
PPT
Stack and queue
PPT
Doublylinklist
PPT
Lecture 14 - Scope Rules
PPT
Stack queue
This pointer
C programming function
Function
Pointers in C/C++ Programming
CHAPTER 6
Array Presentation (EngineerBaBu.com)
CPP Language Basics - Reference
Programming in C (part 2)
Lecture 13 - Storage Classes
Recursion in c++
03 function overloading
Functions
Linq inside out
Functions (Computer programming and utilization)
Swift 3.0 の新しい機能(のうちの9つ)
Linq & lambda overview C#.net
Stack and queue
Doublylinklist
Lecture 14 - Scope Rules
Stack queue
Ad

Similar to Perl 6 command line scripting (20)

PDF
Perl.predefined.variables
PPT
You Can Do It! Start Using Perl to Handle Your Voyager Needs
ODP
Introduction to Perl - Day 2
PPT
LPW: Beginners Perl
PDF
Scripting3
PDF
Perl6 signatures, types and multicall
ODP
Intermediate Perl
PDF
Marc’s (bio)perl course
ODP
Perl Introduction
PPT
Perl tutorial
ODP
Introduction to Perl
PDF
PerlScripting
ODP
Beginning Perl
ODP
Introduction to Perl - Day 1
PPT
Introduction to perl_lists
PDF
Introduction to Perl and BioPerl
PDF
Tutorial perl programming basic eng ver
PPTX
Marcs (bio)perl course
PDF
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Perl.predefined.variables
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Introduction to Perl - Day 2
LPW: Beginners Perl
Scripting3
Perl6 signatures, types and multicall
Intermediate Perl
Marc’s (bio)perl course
Perl Introduction
Perl tutorial
Introduction to Perl
PerlScripting
Beginning Perl
Introduction to Perl - Day 1
Introduction to perl_lists
Introduction to Perl and BioPerl
Tutorial perl programming basic eng ver
Marcs (bio)perl course
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Ad

More from Simon Proctor (9)

PPTX
An introduction to Raku
PDF
Building a raku module
PDF
Multi stage docker
PPTX
Phasers to stunning
PDF
Perl6 operators and metaoperators
PDF
24 uses for perl6
PDF
Perl6 signatures
PPTX
Perl6 a whistle stop tour
PDF
Perl6 a whistle stop tour
An introduction to Raku
Building a raku module
Multi stage docker
Phasers to stunning
Perl6 operators and metaoperators
24 uses for perl6
Perl6 signatures
Perl6 a whistle stop tour
Perl6 a whistle stop tour

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation_ Review paper, used for researhc scholars
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
KodekX | Application Modernization Development
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
cuic standard and advanced reporting.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
Encapsulation_ Review paper, used for researhc scholars
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Review of recent advances in non-invasive hemoglobin estimation
KodekX | Application Modernization Development
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm

Perl 6 command line scripting

  • 1. Perl 6 Command Line Scripting A few tips
  • 2. Hi ● Simon Proctor ● Scimon most places (Twitter etc) ● Senior Developer at Zoopla ● Addicted to Perl6
  • 3. Command Line Switches ● -e : Same as -E in Perl5. Strict mode on and say works. ● -n : Runs the program with $_ set to each line in the given files. Note newlines are stripped from the input lines. ● -p : As -n then say the value of $_ (calls gist on the value and adds a newline). ● -I path : Adds the path for module searches. ● -M module : Loads the given module prior to running the script. Not included -0, -a, -C, -d, -D, -E, -f, -F, -i, -l, -M-, -s, -S, -t, -T, -u, -U, -X Also available PERL6LIB environment variable useful when using prove
  • 4. @*ARGS and $*ARGFILES ● @*ARGS is an Array of all the arguments passed to the programme. ● All arguments are type Str but the Array itself is not typed. ● $*ARGFILES is an IO::CatHandle (actually IO::ArgFiles) object that treats all the values in @*ARGS as paths to files and allows you to iterate over all of them. ● $*ARGFILES is lazily evaluated. It will throw an Exception if the paths do not exist. ● $*ARGFILES is set to $*IN if there are no arguments passed.
  • 5. Welcome to MAIN multi sub MAIN( *@files ) {...} multi sub MAIN( $file1, $file2 ) {...} multi sub MAIN( :$s(size) ) {...} ● @*ARGS is mapped into a signature with a few things to bear in mind ○ All inputs a Str typed but if they match a numeric format they may be a subtype : ■ IntStr, RatStr, ComplexStr, NumStr all are both their appropriate types as required ● Named parameters will be either a Scalar or an Array depending on the number of times they are called. ● Named parameters can also be stored in a slurpy hash *%args.
  • 6. Auto documentation ● Default response to no matching signature is to call the USAGE sub. ● If you want to call the USAGE sub you need to provide one. ● Default is to output the $*USAGE string. ○ Created by reading documentation on all MAIN subs. ○ #| attaches before the thing being documented ○ #= attached after the thing being documented ○ Both are POD directives and will be included in the documentation ○ To discount a MAIN sub from the $*USAGE string creation give it the trait is hidden-from-USAGE
  • 7. Auto documentation : Example multi sub MAIN( :$h? ) is hidden-from-USAGE { USAGE(); } multi sub MAIN( :$h!, *@ ) is hidden-from-USAGE { USAGE(); } #| Sum up some numbers multi sub MAIN( *@nums #= A list of numbers ) { say [+] @nums; } sub USAGE() { say "Highly useful summing thing"; say $*USAGE; } Highly useful summing thing Usage: doc.pl6 [<nums> ...] -- Sum up some numbers [<nums> ...] A list of numbers
  • 8. Tips and Tricks ● END and BEGIN phasers and state variables can be very useful with -n and -p ● my %*SUB-MAIN-OPTS = :named-anywhere; ○ Allows named arguments anywhere in the parsing order. ● subtype Single of Any where * !~~ Positional; ○ Use on a named parameter to ensure only one can be passed. ● Subsets::IO includes a number of useful predefined IO subsets ○ E.G. IO::Path::dw for a writable directory ● For larger scripts move the core code into a module and use you script as a launcher