SlideShare a Scribd company logo
Introductory Perl
AKA LET'S WRITE SOME FUCKING PERL
by William Orr
What do I use Perl for?
• Scripting
• Applications
• Web programming
• Pretty much everything you could want
Why?
• Perl has a very, very large set of available
libraries through CPAN
• TIMTOWTDI
• Language is very flexible - many modules on
CPAN influence behavior of language
How to get Perl - Windows
• dwimperl.com
• Comes with Padre (a Perl "IDE") as well as
tons of useful Perl modules, and an old-ish
version Strawberry Perl
How to get Perl - OSX and Linux
You already have it.
Multiple Perl Installs (you want this)
# cpan
cpan> install App::perlbrew
$ perlbrew init
$ perlbrew install perl-5.16.2
$ perlbrew switch perl-5.16.2
Install other listed modules
How to make Perl more useful
Install some modules
• App::perlbrew
• App::cpanminus
• Const::Fast
• Try::Tiny
• Devel::REPL
Documentation - perldoc
$ perldoc -f <functionname>
$ perldoc <modulename>
$ man perl
Documentation - MetaCPAN
• All the perldoc documentation online and
searchable
• Includes 3rd party docs, links to the bug
tracker, automated testing platforms, authors
website, etc.
Let's write some fucking code
use strict;
use warnings;
use v5.10;
say "WUT UP WRRRRLD";
print "WUT UP WRRRRLDn";
Let's write some fucking code
Things to notice
• use strict
• use warnings
• use v5.10
• say
Let's use some fucking variables
my $first_variable = "This is a scalar";
my $second_variable = 5;
say $first_variable;
say("This is also a scalar: $second_variable");
my $third_variable = 4.5;
say "Guess what else is a fucking scalar?
$third_variable";
my $fourth_variable = qr| d{1,2} / d{1,2} / d{2,4} |x;
say "Also a scalar: $fourth_variable";
Let's use some fucking variables
Things to notice here
• Scalars!
• Interpolation
• Parentheses are optional
Interpolation
• Variables resolve to their value in strings
quoted with "", `` and most other quote-like
operators
I want a lot of scalars!
my @lets_talk_about_arrays = ( "an", "array", "is", "a",
"set", "of", "scalars", "only");
say "@lets_talk_about_arrays";
# We can index into them!
say $lets_talk_about_arrays[1];
# We can do ranges!
say @lets_talk_about_arrays[6..7];
# We can call functions on them!
say join " ", map { uc } @lets_talk_about_arrays[6..7];
say(join(" ", map({ uc } @lets_talk_about_arrays[6..7])));
I want a lot of scalars!
Things to notice here:
• Array declaration & initialization
• Ranges with ..
How do we get array length?
my $array_size = @lets_talk_about_arrays;
say $array_size;
Context
• Functions and operators impose context on
the variables you use
• Context determines result of expression
• Three kinds of context
o scalar
o list
o void
Context
# Scalar context
my $now = localtime;
say $now;
# List context
my @now = localtime;
say "(" . join(", ", @now) . ")";
Context
To review:
• Operators and functions impose context
• Values of expression depend on context
• Arrays used in scalar context return size
• Can force scalar context with scalar()
• Can force list context with ()=
• Documentation!
Dictionar-err, hashes!
my %hash = ( key => "value", other_key => 3, "new key",
5.2 );
say %hash;
say "$hash{key}";
say "$hash{other_key}";
say "$hash{new_key}";
# Scalar context?
say scalar %hash;
# WOAH
my %empty_hash;
say scalar %empty_hash;
Let's talk about operators
• They're all pretty much the same as you're
used to!
• Except for the new ones!
New operators
• . x
• <=>
• cmp, lt, gt, lte, gte, eq, ne
• //
• =~, !~
• or, and, not, xor
• ...
open my $fh, ">", "filename" or die $@;
Control flow - loops
my @some_array = 1..10;
foreach my $iter (@some_array) {
say $iter;
}
my $done = 0;
while (not $done) {
$done = int rand 2;
say $done;
}
Control flow - if
if ($some_var ne "done") {
} elsif ($other_var == 5) {
} else {
}
Control flow - switch
given ($foo) {
when (1) {
}
when (2) {
}
when ("45hundred") {
}
default {
}
}
Special operator - ~~
• Smart match operator
• Returns true based on various, sensible
conditions
• Full table in perlsyn - /Smart matching in
detail
FUCKIT LET'S WRITE SOME
FUNCTIONS
sub my_func {
my ($first, $second, $third) = @_;
return $first + $second + $third;
}
my_func 1, 2, 3
# Array is flattened - will return 6
my @arr = (1, 2, 3, 4, 5, 6);
# NEVER &my_func
SHIT HOW DO I NOT FLATTEN
ARRAYS IN FUNCTION CALLS?!
• or also "HOW THE HELL CAN I HAVE
COMPOSITE DATA STRUCTURES?!"
Let's talk about references
• Can pass around references to _anything_
o this includes functions
• A reference is a scalar - can pop arrays into
arrays
• When you modify the value of a reference, it
modifies the original variable
Let's talk about references
my @arr = ( 1 .. 10 );
# This won't compile
#my @two_d_arr = ( @arr, @arr );
my @two_d_arr = ( @arr, @arr );
# We'll see some reference addresses
say "@two_d_arr";
# One reference address
say $two_d_arr[0];
# Dereferencing
say "@{$two_d_arr[0]}";
Let's talk about references
# Hashes?
# YOU'RE DAMN RIGHT
my %hash;
$hash{first} = @arr;
say $hash{first}->[0];
# OR
say ${hash{first}}->[0];
# Lets get fancy
$hash{second} = %hash;
say $hash{second}->{first}->[0];
Let's talk about references
sub print_shit {
say "shit";
}
$hash{third} = &print_shit;
$hash{third}->();
Anonymous references
my $arr_ref = [ 1, 2, 3, 4 ];
say @$arr_ref;
say scalar @$arr_ref;
say $arr_ref->[1]
my $hash_ref = { key => 1, other_key => 5 };
say %$hash_ref;
say $hash_ref->{key};
my $sub_ref = sub { say "foo"; }
$sub_ref->();
Anonymous references
• anonymous array references declared with []
• anon hash refs declared with {}
• anon sub refs declared with sub { }
File I/O
open(my $fh, "<", "testfile") or die "Could not open file
for reading";
foreach my $line (<$fh>) {
print $line;
}
close($fh);
open($fh, ">>", "testfile") or die "Could not open file
for writing";
say $fh "let's append a message";
close($fh);
Let's run some commands
open(my $cmd, "-|", "ls") or die "Could not run ls";
foreach my $line (<$cmd>) {
print $line;
}
close($cmd);
open($cmd, "|-", "cat") or die "Could not run cat";
say $cmd "cat'd output";
close($cmd);
my $output = qx/ls/; # `` also works
foreach my $line (split /n/, $output) {
say $line;
}
In conclusion
This is some basic Perl, and is not even close
to conclusive

More Related Content

What's hot

Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
Lin Yo-An
 
Perl basics for pentesters part 2
Perl basics for pentesters part 2Perl basics for pentesters part 2
Perl basics for pentesters part 2
n|u - The Open Security Community
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
heumann
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
Workhorse Computing
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
Workhorse Computing
 
05php
05php05php
rtwerewr
rtwerewrrtwerewr
rtwerewr
esolinhighered
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
Workhorse Computing
 
Findbin libs
Findbin libsFindbin libs
Findbin libs
Workhorse Computing
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
brian d foy
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
Workhorse Computing
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
Kang-min Liu
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
Dave Cross
 
Refactoring Infrastructure Code
Refactoring Infrastructure CodeRefactoring Infrastructure Code
Refactoring Infrastructure Code
Nell Shamrell-Harrington
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
Workhorse Computing
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
Workhorse Computing
 
Ruby 2.0
Ruby 2.0Ruby 2.0
Ruby 2.0
Uģis Ozols
 
Migrating to Puppet 4.0
Migrating to Puppet 4.0Migrating to Puppet 4.0
Migrating to Puppet 4.0
Puppet
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a boss
gsterndale
 

What's hot (20)

Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Perl basics for pentesters part 2
Perl basics for pentesters part 2Perl basics for pentesters part 2
Perl basics for pentesters part 2
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
05php
05php05php
05php
 
rtwerewr
rtwerewrrtwerewr
rtwerewr
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
Findbin libs
Findbin libsFindbin libs
Findbin libs
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Refactoring Infrastructure Code
Refactoring Infrastructure CodeRefactoring Infrastructure Code
Refactoring Infrastructure Code
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Ruby 2.0
Ruby 2.0Ruby 2.0
Ruby 2.0
 
Migrating to Puppet 4.0
Migrating to Puppet 4.0Migrating to Puppet 4.0
Migrating to Puppet 4.0
 
Refactor like a boss
Refactor like a bossRefactor like a boss
Refactor like a boss
 

Viewers also liked

Perl intro
Perl introPerl intro
Perl intro
Swapnesh Singh
 
Introduction to perl_ a scripting language
Introduction to perl_ a scripting languageIntroduction to perl_ a scripting language
Introduction to perl_ a scripting language
Vamshi Santhapuri
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
tutorialsruby
 
POD2::* and Perl translation documentation project
POD2::* and Perl translation documentation projectPOD2::* and Perl translation documentation project
POD2::* and Perl translation documentation project
Enrico Sorcinelli
 
perl-java
perl-javaperl-java
perl-java
tutorialsruby
 
Perl 101 - The Basics of Perl Programming
Perl  101 - The Basics of Perl ProgrammingPerl  101 - The Basics of Perl Programming
Perl 101 - The Basics of Perl Programming
Utkarsh Sengar
 
pickingUpPerl
pickingUpPerlpickingUpPerl
pickingUpPerl
tutorialsruby
 
Perl
PerlPerl
Perl
Tiago
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
Elie Obeid
 
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
Ricardo Signes
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
Varadharajan Mukundan
 

Viewers also liked (11)

Perl intro
Perl introPerl intro
Perl intro
 
Introduction to perl_ a scripting language
Introduction to perl_ a scripting languageIntroduction to perl_ a scripting language
Introduction to perl_ a scripting language
 
PerlIntro
PerlIntroPerlIntro
PerlIntro
 
POD2::* and Perl translation documentation project
POD2::* and Perl translation documentation projectPOD2::* and Perl translation documentation project
POD2::* and Perl translation documentation project
 
perl-java
perl-javaperl-java
perl-java
 
Perl 101 - The Basics of Perl Programming
Perl  101 - The Basics of Perl ProgrammingPerl  101 - The Basics of Perl Programming
Perl 101 - The Basics of Perl Programming
 
pickingUpPerl
pickingUpPerlpickingUpPerl
pickingUpPerl
 
Perl
PerlPerl
Perl
 
Perl programming language
Perl programming languagePerl programming language
Perl programming language
 
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
 
Perl Scripting
Perl ScriptingPerl Scripting
Perl Scripting
 

Similar to Introduction to Perl

php fundamental
php fundamentalphp fundamental
php fundamental
zalatarunk
 
php
phpphp
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
pooja bhandari
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
BUDNET
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
Dave Cross
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
Dave Cross
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
Lorna Mitchell
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
Rakesh Mukundan
 
Scripting3
Scripting3Scripting3
Scripting3
Nao Dara
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
Cyber Security Infotech Pvt. Ltd.
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Roy Zimmer
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
Anshu Prateek
 
05php
05php05php
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
Dave Cross
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Marc’s (bio)perl course
Marc’s (bio)perl courseMarc’s (bio)perl course
Marc’s (bio)perl course
Marc Logghe
 
05php
05php05php
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
David Golden
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
Vibrant Technologies & Computers
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
Dave Cross
 

Similar to Introduction to Perl (20)

php fundamental
php fundamentalphp fundamental
php fundamental
 
php
phpphp
php
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
MIND sweeping introduction to PHP
MIND sweeping introduction to PHPMIND sweeping introduction to PHP
MIND sweeping introduction to PHP
 
Introduction to Perl - Day 1
Introduction to Perl - Day 1Introduction to Perl - Day 1
Introduction to Perl - Day 1
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Practical approach to perl day1
Practical approach to perl day1Practical approach to perl day1
Practical approach to perl day1
 
Scripting3
Scripting3Scripting3
Scripting3
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
 
You Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager NeedsYou Can Do It! Start Using Perl to Handle Your Voyager Needs
You Can Do It! Start Using Perl to Handle Your Voyager Needs
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
05php
05php05php
05php
 
Beginning Perl
Beginning PerlBeginning Perl
Beginning Perl
 
Intro to Perl and Bioperl
Intro to Perl and BioperlIntro to Perl and Bioperl
Intro to Perl and Bioperl
 
Marc’s (bio)perl course
Marc’s (bio)perl courseMarc’s (bio)perl course
Marc’s (bio)perl course
 
05php
05php05php
05php
 
Adventures in Optimization
Adventures in OptimizationAdventures in Optimization
Adventures in Optimization
 
Php classes in mumbai
Php classes in mumbaiPhp classes in mumbai
Php classes in mumbai
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 

Recently uploaded

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 

Recently uploaded (20)

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 

Introduction to Perl

  • 1. Introductory Perl AKA LET'S WRITE SOME FUCKING PERL by William Orr
  • 2. What do I use Perl for? • Scripting • Applications • Web programming • Pretty much everything you could want
  • 3. Why? • Perl has a very, very large set of available libraries through CPAN • TIMTOWTDI • Language is very flexible - many modules on CPAN influence behavior of language
  • 4. How to get Perl - Windows • dwimperl.com • Comes with Padre (a Perl "IDE") as well as tons of useful Perl modules, and an old-ish version Strawberry Perl
  • 5. How to get Perl - OSX and Linux You already have it.
  • 6. Multiple Perl Installs (you want this) # cpan cpan> install App::perlbrew $ perlbrew init $ perlbrew install perl-5.16.2 $ perlbrew switch perl-5.16.2 Install other listed modules
  • 7. How to make Perl more useful Install some modules • App::perlbrew • App::cpanminus • Const::Fast • Try::Tiny • Devel::REPL
  • 8. Documentation - perldoc $ perldoc -f <functionname> $ perldoc <modulename> $ man perl
  • 9. Documentation - MetaCPAN • All the perldoc documentation online and searchable • Includes 3rd party docs, links to the bug tracker, automated testing platforms, authors website, etc.
  • 10. Let's write some fucking code use strict; use warnings; use v5.10; say "WUT UP WRRRRLD"; print "WUT UP WRRRRLDn";
  • 11. Let's write some fucking code Things to notice • use strict • use warnings • use v5.10 • say
  • 12. Let's use some fucking variables my $first_variable = "This is a scalar"; my $second_variable = 5; say $first_variable; say("This is also a scalar: $second_variable"); my $third_variable = 4.5; say "Guess what else is a fucking scalar? $third_variable"; my $fourth_variable = qr| d{1,2} / d{1,2} / d{2,4} |x; say "Also a scalar: $fourth_variable";
  • 13. Let's use some fucking variables Things to notice here • Scalars! • Interpolation • Parentheses are optional
  • 14. Interpolation • Variables resolve to their value in strings quoted with "", `` and most other quote-like operators
  • 15. I want a lot of scalars! my @lets_talk_about_arrays = ( "an", "array", "is", "a", "set", "of", "scalars", "only"); say "@lets_talk_about_arrays"; # We can index into them! say $lets_talk_about_arrays[1]; # We can do ranges! say @lets_talk_about_arrays[6..7]; # We can call functions on them! say join " ", map { uc } @lets_talk_about_arrays[6..7]; say(join(" ", map({ uc } @lets_talk_about_arrays[6..7])));
  • 16. I want a lot of scalars! Things to notice here: • Array declaration & initialization • Ranges with ..
  • 17. How do we get array length? my $array_size = @lets_talk_about_arrays; say $array_size;
  • 18. Context • Functions and operators impose context on the variables you use • Context determines result of expression • Three kinds of context o scalar o list o void
  • 19. Context # Scalar context my $now = localtime; say $now; # List context my @now = localtime; say "(" . join(", ", @now) . ")";
  • 20. Context To review: • Operators and functions impose context • Values of expression depend on context • Arrays used in scalar context return size • Can force scalar context with scalar() • Can force list context with ()= • Documentation!
  • 21. Dictionar-err, hashes! my %hash = ( key => "value", other_key => 3, "new key", 5.2 ); say %hash; say "$hash{key}"; say "$hash{other_key}"; say "$hash{new_key}"; # Scalar context? say scalar %hash; # WOAH my %empty_hash; say scalar %empty_hash;
  • 22. Let's talk about operators • They're all pretty much the same as you're used to! • Except for the new ones!
  • 23. New operators • . x • <=> • cmp, lt, gt, lte, gte, eq, ne • // • =~, !~ • or, and, not, xor • ... open my $fh, ">", "filename" or die $@;
  • 24. Control flow - loops my @some_array = 1..10; foreach my $iter (@some_array) { say $iter; } my $done = 0; while (not $done) { $done = int rand 2; say $done; }
  • 25. Control flow - if if ($some_var ne "done") { } elsif ($other_var == 5) { } else { }
  • 26. Control flow - switch given ($foo) { when (1) { } when (2) { } when ("45hundred") { } default { } }
  • 27. Special operator - ~~ • Smart match operator • Returns true based on various, sensible conditions • Full table in perlsyn - /Smart matching in detail
  • 28. FUCKIT LET'S WRITE SOME FUNCTIONS sub my_func { my ($first, $second, $third) = @_; return $first + $second + $third; } my_func 1, 2, 3 # Array is flattened - will return 6 my @arr = (1, 2, 3, 4, 5, 6); # NEVER &my_func
  • 29. SHIT HOW DO I NOT FLATTEN ARRAYS IN FUNCTION CALLS?! • or also "HOW THE HELL CAN I HAVE COMPOSITE DATA STRUCTURES?!"
  • 30. Let's talk about references • Can pass around references to _anything_ o this includes functions • A reference is a scalar - can pop arrays into arrays • When you modify the value of a reference, it modifies the original variable
  • 31. Let's talk about references my @arr = ( 1 .. 10 ); # This won't compile #my @two_d_arr = ( @arr, @arr ); my @two_d_arr = ( @arr, @arr ); # We'll see some reference addresses say "@two_d_arr"; # One reference address say $two_d_arr[0]; # Dereferencing say "@{$two_d_arr[0]}";
  • 32. Let's talk about references # Hashes? # YOU'RE DAMN RIGHT my %hash; $hash{first} = @arr; say $hash{first}->[0]; # OR say ${hash{first}}->[0]; # Lets get fancy $hash{second} = %hash; say $hash{second}->{first}->[0];
  • 33. Let's talk about references sub print_shit { say "shit"; } $hash{third} = &print_shit; $hash{third}->();
  • 34. Anonymous references my $arr_ref = [ 1, 2, 3, 4 ]; say @$arr_ref; say scalar @$arr_ref; say $arr_ref->[1] my $hash_ref = { key => 1, other_key => 5 }; say %$hash_ref; say $hash_ref->{key}; my $sub_ref = sub { say "foo"; } $sub_ref->();
  • 35. Anonymous references • anonymous array references declared with [] • anon hash refs declared with {} • anon sub refs declared with sub { }
  • 36. File I/O open(my $fh, "<", "testfile") or die "Could not open file for reading"; foreach my $line (<$fh>) { print $line; } close($fh); open($fh, ">>", "testfile") or die "Could not open file for writing"; say $fh "let's append a message"; close($fh);
  • 37. Let's run some commands open(my $cmd, "-|", "ls") or die "Could not run ls"; foreach my $line (<$cmd>) { print $line; } close($cmd); open($cmd, "|-", "cat") or die "Could not run cat"; say $cmd "cat'd output"; close($cmd); my $output = qx/ls/; # `` also works foreach my $line (split /n/, $output) { say $line; }
  • 38. In conclusion This is some basic Perl, and is not even close to conclusive