Perl 101
An introduction to the Perl programming language

Alex Balhatchet @ Makers Academy, November 2013
Who Am I?
Who’s this guy?
● Alex Balhatchet
● CTO at Nestoria property search engine
● Programming Perl for 12 years
● Hiring, train...
Nestoria
● Property search engine
● Operating in 8 countries, 6 languages
● Serving 1.3 million search requests per day
● ...
Nestoria
Perl History
What is Perl?
Perl 5 is a high-level, general purpose,
interpreted, dynamic programming language.
It was largely inspired ...
So, Perl
● 1.0 released in 1987
● 5.0 released in 1994
● Language is now “Perl 5”
● Perl 6 is a new language separate from...
So, Perl 5
● Annual releases since 2010
● Perl 5.18 was released May 2013
● Perl 5.20 will be released May 2014
● New rele...
Perl Philosophy
TIMTOWTDI
TIMTOWTDI is pronounced “Tim Toady” and is:

There is more than one way to do it
Perl aims to be aggressively no...
Making easy things easy
& hard things possible
This quote comes from the front of Learning
Perl, also known as the Llama.
...
Do What I Mean
Perl’s creator Larry Wall has a linguistics
background, and took some of that with him
when he designed Per...
Low Ambiguity
In many languages this is
acceptable:

In Perl we use different
operators:

puts 1 + 2
puts "a" + "b"

say 1...
Perl Syntax
Variables - Scalars
$foo = 1;

$bar = 3.14195;

$str = "Hello, World!";
Variables - Arrays
@things = (1, 2, 3);

$things[2]; # 3

join(",", @things); # 1,2,3,4
Variables - Hashes
%hash = (
key => "value",
foo => $bar,
thingies => "whatsits",
);
say $hash{key}; # "value"
Variables - Data Structures
$alex_hashref = {
name => {
first => "Alex",
last => "Balhatchet",
},
languages => [
"English"...
Conditionals
if ($true) {
say "It’s true!";
}
say "It’s true too!" if $true_two;
Loops
for $i (1 .. 20) {
say $i * $i;
}
while ($line = <STDIN>) {
say length $line;
}
Regular Expressions - Matching
$str = "Hello, Makers Academy!";
if ($str =~ m/makers/i) {
say "matched!";
}
else {
say "no...
Regular Expressions - Matching
$num = -1.23456;
if ($num =~ m/^ [+-]? d+ ([.]d+)? $/x) {
say "looks like a number!";
}
els...
Regular Expressions - Substitutions
$str = "Hello, Makers Academy!";
$str =~ s/Makers Academy/Makers!/;
say $str; # Hello,...
Subroutines
sub add {
($num_a, $num_b) = @_;
return $num_a + $num_b;
}
say add(3, 4);
# 7
say add(-3, 3);
# 0
say add(1/3,...
Objects
package MyClass;

use MyClass;

sub new {

$Object = MyClass->new();

($class) = @_;
return bless {}, $class;
}
su...
Perl Advantages
Perl Advantages
CPAN
CPAN
CPAN stands for Comprehensive Perl Archive
Network, and is a collection of Perl modules.
You can browse CPAN at cpan....
CPAN Modules
Web Frameworks (Catalyst, Dancer, Mojo)
ORMs (DBIx::Class, Fey, Norma)
Serialization (XML::Simple, JSON)
Math...
Perl Advantages
Unicode
Unicode
Perl was made with text manipulation in mind,
and has excellent support for Unicode.
All of Perl’s builtin functio...
Unicode Examples
use utf8::all;
$str = "Schwanhäußerstraße";
say $str;

# Schwanhäußerstraße

say length $str;

# 18

$str...
Perl Advantages
Testing
Testing
Perl has a big testing culture.
Most CPAN modules have a test suite!
There are also a good number of CPAN
modules ...
Testing Example
use Test::More tests => 3;

~$ prove -v example.t
example.t ..

ok 1, "1 is true";

1..3
ok 1 - 1 is true
...
Perl Advantages
Community
Perl Community
Monthly social meetings (London.pm)
Bi-monthly technical meetings (London.pm)
Free conference (London Perl ...
Free Resources
http://learn.perl.org
http://modernperlbooks.com
http://blogs.perl.org
http://perldoc.perl.org
Perl Advantages
Jobs
Perl developers are in demand
We are hiring… and so is pretty much every
other Perl company!
http://lokku.com/jobs
http://...
Perl at Nestoria
Nestoria
Nestoria Listings Processing
● XML parsing
● Geocoding
● Natural language processing
● De-duplication
● Image thumbnailing
The Nestoria Website
● Apache + mod_perl
● Templating with HTML::Mason
● Maketext (and Locale::Maketext) for translations
...
Other Stuff :-)
● geodata system
● Continuous testing and deployment
● Metrics processing system
● Automated PDF and Excel...
Summary
Summary
● Perl has a rich history and an exciting future
● Perl is a straightforward, easy to learn language
● Perl has a ...
Thanks!
Questions?
ht Nes
tp to
:// ri
lo a
kk is
u. Hi
co ri
m ng
/jo !
bs

Thanks!
@kaokun
@nestoria

http://github.com/lokku
Upcoming SlideShare
Loading in...5
×

Perl 101

1,891

Published on

An Introduction for Perl, presented to two Makers Academy cohorts on Monday November 4th 2013.

Makers Academy is a 12 week intensive course teaching Ruby and web development. This presentation was intended to give them an introduction to another language they might be interested in picking up to widen their range of skills.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,891
On Slideshare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Perl 101

  1. 1. Perl 101 An introduction to the Perl programming language Alex Balhatchet @ Makers Academy, November 2013
  2. 2. Who Am I?
  3. 3. Who’s this guy? ● Alex Balhatchet ● CTO at Nestoria property search engine ● Programming Perl for 12 years ● Hiring, training and mentoring Perl interns and permanent hires for 4 years
  4. 4. Nestoria ● Property search engine ● Operating in 8 countries, 6 languages ● Serving 1.3 million search requests per day ● 85% Perl, 5% JavaScript, 5% C, 5% Other
  5. 5. Nestoria
  6. 6. Perl History
  7. 7. What is Perl? Perl 5 is a high-level, general purpose, interpreted, dynamic programming language. It was largely inspired by grep, sed, awk, and C. It influenced Python, Ruby, and PHP.
  8. 8. So, Perl ● 1.0 released in 1987 ● 5.0 released in 1994 ● Language is now “Perl 5” ● Perl 6 is a new language separate from, but related to, Perl 5
  9. 9. So, Perl 5 ● Annual releases since 2010 ● Perl 5.18 was released May 2013 ● Perl 5.20 will be released May 2014 ● New releases contain new features, bug fixes, and performance improvements
  10. 10. Perl Philosophy
  11. 11. TIMTOWTDI TIMTOWTDI is pronounced “Tim Toady” and is: There is more than one way to do it Perl aims to be aggressively non-prescriptivist. Every problem should have multiple solutions.
  12. 12. Making easy things easy & hard things possible This quote comes from the front of Learning Perl, also known as the Llama. It goes hand-in-hand with TIMTOWTDI. Every problem has multiple solutions implies every problem has at least one solution :-)
  13. 13. Do What I Mean Perl’s creator Larry Wall has a linguistics background, and took some of that with him when he designed Perl. Keywords such as “for”, “my”, “defined”, “say”, “do”, “while”, “if”, “unless”, and “use” all read quite nicely to English eyes as well as to programmer eyes.
  14. 14. Low Ambiguity In many languages this is acceptable: In Perl we use different operators: puts 1 + 2 puts "a" + "b" say 1 + 2; say "a" . "b"; # 3 # "ab" say "2" + 1; say "2" . 1; # 3 # 21 # 3 # "ab" puts "2" + 1 # !! in `+': can't convert Fixnum into String (TypeError)
  15. 15. Perl Syntax
  16. 16. Variables - Scalars $foo = 1; $bar = 3.14195; $str = "Hello, World!";
  17. 17. Variables - Arrays @things = (1, 2, 3); $things[2]; # 3 join(",", @things); # 1,2,3,4
  18. 18. Variables - Hashes %hash = ( key => "value", foo => $bar, thingies => "whatsits", ); say $hash{key}; # "value"
  19. 19. Variables - Data Structures $alex_hashref = { name => { first => "Alex", last => "Balhatchet", }, languages => [ "English", "German", "Perl" ], };
  20. 20. Conditionals if ($true) { say "It’s true!"; } say "It’s true too!" if $true_two;
  21. 21. Loops for $i (1 .. 20) { say $i * $i; } while ($line = <STDIN>) { say length $line; }
  22. 22. Regular Expressions - Matching $str = "Hello, Makers Academy!"; if ($str =~ m/makers/i) { say "matched!"; } else { say "no match :-("; }
  23. 23. Regular Expressions - Matching $num = -1.23456; if ($num =~ m/^ [+-]? d+ ([.]d+)? $/x) { say "looks like a number!"; } else { say "that’s no number I ever saw..."; }
  24. 24. Regular Expressions - Substitutions $str = "Hello, Makers Academy!"; $str =~ s/Makers Academy/Makers!/; say $str; # Hello, Makers!!
  25. 25. Subroutines sub add { ($num_a, $num_b) = @_; return $num_a + $num_b; } say add(3, 4); # 7 say add(-3, 3); # 0 say add(1/3, 2/3); # 1
  26. 26. Objects package MyClass; use MyClass; sub new { $Object = MyClass->new(); ($class) = @_; return bless {}, $class; } sub add { ($self, $n1, $n2) = @_; return $n1 + $n2; } say $Object->add(123, 456);
  27. 27. Perl Advantages
  28. 28. Perl Advantages CPAN
  29. 29. CPAN CPAN stands for Comprehensive Perl Archive Network, and is a collection of Perl modules. You can browse CPAN at cpan.org Today CPAN contains 126,892 Perl modules in 28,607 distributions, written by 11,031 authors, mirrored on 271 servers.
  30. 30. CPAN Modules Web Frameworks (Catalyst, Dancer, Mojo) ORMs (DBIx::Class, Fey, Norma) Serialization (XML::Simple, JSON) Maths (Math::Random::MT, Statistics::TTest, Geo::Distance)
  31. 31. Perl Advantages Unicode
  32. 32. Unicode Perl was made with text manipulation in mind, and has excellent support for Unicode. All of Perl’s builtin functions, including regular expressions, are Unicode safe. Many CPAN modules that deal with text will also have considered encoding issues.
  33. 33. Unicode Examples use utf8::all; $str = "Schwanhäußerstraße"; say $str; # Schwanhäußerstraße say length $str; # 18 $str = uc $str; say $str; # SCHWANHÄUSSERSTRASSE say substr $str, 7, 1; # Ä if ($str =~ m/schwanhäußerstraße/i) { say "I N{HEAVY BLACK HEART} Perl"; } # I ❤ Perl
  34. 34. Perl Advantages Testing
  35. 35. Testing Perl has a big testing culture. Most CPAN modules have a test suite! There are also a good number of CPAN modules to help you with testing your code.
  36. 36. Testing Example use Test::More tests => 3; ~$ prove -v example.t example.t .. ok 1, "1 is true"; 1..3 ok 1 - 1 is true is 1 + 1, 2, "1 + 1 = 2"; ok 2 - 1 + 1 = 2 ok 3 - got expected array @a = sort (4, 2, 3, 1); ok is_deeply( All tests successful. @a, [ 1, 2, 3, 4 ], "got expected array" ); Files=1, Tests=3, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.02 cusr 0.00 csys = 0.04 CPU) Result: PASS
  37. 37. Perl Advantages Community
  38. 38. Perl Community Monthly social meetings (London.pm) Bi-monthly technical meetings (London.pm) Free conference (London Perl Workshop) See the world! YAPC::EU, YAPC::NA, YAPC:: Russia, YAPC::SA, YAPC::Asia, and YAPC:: Australia
  39. 39. Free Resources http://learn.perl.org http://modernperlbooks.com http://blogs.perl.org http://perldoc.perl.org
  40. 40. Perl Advantages Jobs
  41. 41. Perl developers are in demand We are hiring… and so is pretty much every other Perl company! http://lokku.com/jobs http://jobs.perl.org
  42. 42. Perl at Nestoria
  43. 43. Nestoria
  44. 44. Nestoria Listings Processing ● XML parsing ● Geocoding ● Natural language processing ● De-duplication ● Image thumbnailing
  45. 45. The Nestoria Website ● Apache + mod_perl ● Templating with HTML::Mason ● Maketext (and Locale::Maketext) for translations ● Query Analysis / Geographic lookup ● Spell checking and fuzzy matching ● Super fast (90% requests under 200ms)
  46. 46. Other Stuff :-) ● geodata system ● Continuous testing and deployment ● Metrics processing system ● Automated PDF and Excel file “end of month” reports ● Email Alerts ● Average House Prices
  47. 47. Summary
  48. 48. Summary ● Perl has a rich history and an exciting future ● Perl is a straightforward, easy to learn language ● Perl has a lot of advantages (CPAN, Unicode, & Jobs!) ● At Nestoria we’ve shown that Perl can be the foundation of a highly successful and technically sophisticated startup business
  49. 49. Thanks!
  50. 50. Questions?
  51. 51. ht Nes tp to :// ri lo a kk is u. Hi co ri m ng /jo ! bs Thanks! @kaokun @nestoria http://github.com/lokku
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×