Perls of wisdom
Download
1 / 20

Phase One: Intro to Perl - PowerPoint PPT Presentation


  • 355 Views
  • Updated On :

Perls of Wisdom. Introduction. PERL - Practical Extraction and Report Language Larry Wall Author of USENET reader rn and patch Extensive training as linguist. English, Reality, and Perl. Reality is a mess. Since English is also a mess, it maps well onto reality.

Related searches for Phase One: Intro to Perl

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Phase One: Intro to Perl' - jaden


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Introduction
Introduction

  • PERL - Practical Extraction and Report Language

  • Larry Wall

  • Author of USENET reader rn and patch

  • Extensive training as linguist


English reality and perl
English, Reality, and Perl

  • Reality is a mess.

  • Since English is also a mess, it maps well onto reality.

  • Perl was designed to be messy (in the nicest possible way.)

  • Modeled after natural languages; constructs can be complex but meaningful without being wordy (unlike this slide, which is very wordy).


Perl on simplicity
Perl on Simplicity

  • Perl can be simple, and do many useful things, or it can be complex, and work magic. (Complexity does not necessarily equal code length.)


The creation of perl
The Creation of Perl

  • Originally, made to just be a text processing language.

  • Larry wanted to fill the void between “manipulexity”and “whipupitude”.

  • Perl violates a rule of Unix: a tool should do one thing, and do it well.


Perl of wisdom 1
Perl of Wisdom #1

  • There is more than one way to do it.


Don t have mad skills
Don’t have mad skills?

  • A little bit of Perl can go a long way. A 3 year old can speak English and be understood, despite having a very limited vocabulary.

  • The same language spoken by a 3 year old is used by philosophers and geniuses to explain extremely complex things.


If all else fails what would george do
If all else fails, What Would George Do?

  • George Would Read The Fine Manual

  • man perl

  • If man pages aren’t your thing, perhaps you should invest in a good book.

  • -w is your friend.


Perl of wisdom 2
Perl of Wisdom #2

  • Easy things should be easy, hard things should be possible

  • A camel is ugly, stinky, and spits, but gets you where you're going.


Howdy y all
Howdy Y’all

This is your first coding project in Perl.

#!/usr/bin/perl

print “Howdy Y’all”;

* Note this is an exercise in using the Perl interpreter.


Variable syntax or funny characters you will meet on your journey with perl
Variable Syntax(or, funny characters you will meet on your journey with Perl…)


Perl is type free
Perl Is Type Free

$answer = 42; # integer

$pi = 3.14159265; # a float

$university = “Drexel”; # a string

$interp = “I go to $university”; # string + interpolation

$noninterp = ‘Its too much $$’; # string – interpolation

$output = `pwd`; # output from a shell command

$status = system(“vi $x”); # status of a command

$dog = new Camel “Fido”; # instantiation of an object


Arrays in perl
Arrays in Perl

@nounsare = (“people”, “places”, “things”);

Arrays in Perl generally behave the same way they do in C.

$howmanynouns = @nounsare;


Loops
Loops

  • While

    while (condition) {do this in here;

    }

  • For

    for ($i = 1; $i < 10; $i++) {

    ...

    }

  • Foreach

    foreach $element (@elements) {

    do this here

    }


Filehandles
Filehandles

  • Allow Perl to interact with real world stuff.

  • Please close your files.

open(SESAME, “filename”) # read from existing

open(SESAME, “>filename”) # create file and write to it

open(SESAME, “>>filename”) # open existing file and append

close(SESAME); # no one likes to see you with

# your files open anyway...


Playing with filehandles
Playing With Filehandles

A Simple Example:

All of these are the same thing.

while (<SESAME>) { print $_; } # Don’t panic, I’ll explain the $_

while (<SESAME>) { print; } # Here the $_ is implied

print while <SESAME>;

Output into files:

print SESAME “This goes out to the file.”


Interesting functions i ve met
Interesting Functions I’ve Met.

  • print.

    Not only used as: print “blah”;

    Try: print << bigblock; # This is more of a print until

    print this # you hit the label bigblock

    and this

    bigblock;

  • chomp and chop.

    When taking in strings from files, used to remove last character (usually an annoying newline that can mess things up).

    chomp is safer, returns # of characters eaten chop returns character eaten

  • split.


Cartwheels and backticks
Cartwheels and Backticks

  • Backticks (` `) can be used to execute commands in a shell.

    $info = `finger $user` # Returns all output from command as a string

    # Note interpolation


Your last perl of wisdom
Your Last Perl of Wisdom

  • Perl gives the programmer as much rope as he or she desires.

  • It’s always enough rope to hang yourself with.


The whole
The Whole #!

  • Applied Perl

  • Perls of Wisdom


ad