Perl 101
Upcoming SlideShare
Loading in...5
×
 

Perl 101

on

  • 1,775 views

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

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.

Statistics

Views

Total Views
1,775
Views on SlideShare
1,227
Embed Views
548

Actions

Likes
0
Downloads
31
Comments
0

10 Embeds 548

http://blogs.perl.org 472
http://cloud.feedly.com 58
http://www.feedspot.com 5
http://news.int80.biz 5
http://digg.com 2
http://www.newsblur.com 2
http://inoreader.com 1
http://newsblur.com 1
http://reader.aol.com 1
http://feedly.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Perl 101 Perl 101 Presentation Transcript

  • 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, training and mentoring Perl interns and permanent hires for 4 years
  • 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
  • Nestoria
  • Perl History
  • 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.
  • 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
  • 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
  • Perl Philosophy
  • 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.
  • 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 :-)
  • 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.
  • 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)
  • 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", "German", "Perl" ], };
  • 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 match :-("; }
  • 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..."; }
  • Regular Expressions - Substitutions $str = "Hello, Makers Academy!"; $str =~ s/Makers Academy/Makers!/; say $str; # Hello, Makers!!
  • 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
  • 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);
  • 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.org Today CPAN contains 126,892 Perl modules in 28,607 distributions, written by 11,031 authors, mirrored on 271 servers.
  • CPAN Modules Web Frameworks (Catalyst, Dancer, Mojo) ORMs (DBIx::Class, Fey, Norma) Serialization (XML::Simple, JSON) Maths (Math::Random::MT, Statistics::TTest, Geo::Distance)
  • Perl Advantages Unicode
  • 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.
  • 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
  • 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 to help you with testing your code.
  • 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
  • Perl Advantages Community
  • 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
  • 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://jobs.perl.org
  • 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 ● Query Analysis / Geographic lookup ● Spell checking and fuzzy matching ● Super fast (90% requests under 200ms)
  • 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
  • Summary
  • 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
  • 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