Perls of wisdom
Download
1 / 20

Perls of Wisdom - PowerPoint PPT Presentation

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 Perls of Wisdom

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

Download Presentation

Perls of Wisdom

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


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.

  • 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 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

  • 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

  • There is more than one way to do it.


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?

  • 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

  • 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

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…)


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

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

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

$howmanynouns = @nounsare;


Loops

  • While

    while (condition) {do this in here;

    }

  • For

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

    ...

    }

  • Foreach

    foreach $element (@elements) {

    do this here

    }


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

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.

  • 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 eatenchop returns character eaten

  • split.


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

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

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


The Whole #!

  • Applied Perl

  • Perls of Wisdom


ad
  • Login