39
Language Popularity Perl PHP References Scripting languages: Perl and PHP Tuukka Haapasalo December 1, 2009 Tuukka Haapasalo Scripting languages: Perl and PHP

Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

  • Upload
    dinhanh

  • View
    249

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Scripting languages: Perl and PHP

Tuukka Haapasalo

December 1, 2009

Tuukka HaapasaloScripting languages: Perl and PHP

Page 2: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Outline

1 Language Popularity

2 PerlIntroductionHistorySyntax

3 PHPIntroductionHistory

4 References

Tuukka HaapasaloScripting languages: Perl and PHP

Page 3: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Popularity of Programming Languages [3, 10]

Tuukka HaapasaloScripting languages: Perl and PHP

Page 4: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Perl

Tuukka HaapasaloScripting languages: Perl and PHP

Page 5: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Write-only code?$_=’ev

al (" seek \040DATA ,0, 0;"); foreach (1..3)

{<DATA >;} my @camel1hump ; my$camel ;my$Camel ; while ( <DATA >){ $_= sprintf ("% -6

9s",$_ ); my@dromedary 1= split (//); if( defined ($_=<DATA >)){ @camel1hum p= split (//);} while ( @dromeda

ry1 ){ my$camel1hump =0 ; my$CAMEL =3; if( defined ($_=shift( @dromedary1 ))&&/\ S/){ $camel1hump +=1<< $CAMEL ;}

$CAMEL --;if(d efined ($_= shift ( @dromedary1 ))&&/\ S/){$camel1hump +=1 <<$CAMEL ;} $CAMEL --;if( defined ($_= shift (

@camel1hump ))&&/\ S/){ $camel1hump +=1<< $CAMEL ;} $CAMEL --;if(defined ($_= shift ( @camel1hump ))&&/\ S/){ $camel1hump +=1<< $CAMEL;;} $camel .=( split (// ,"\040..m ‘{/J \047\134} L^7 FX "))[ $camel1h

ump ];} $camel .="\n";} @camel1hump = split (/\n/, $camel ); foreach (@camel1hump ){ chomp ; $Camel =$_;y/LJF7 \173\175 ‘\047/\061\062\063\064\065\066\067\070/; y /12345678/ JL7F \175\173\047 ‘/; $_= reverse ;

print "$_ \040 $Camel \n";} foreach ( @camel1hump ){ chomp ; $Camel =$_;y/LJF7 \173\175 ‘\047/12345678/; y /12345678/ JL7F \175\173\0 47 ‘/;

$_= reverse ; print "\040 $_$Camel \n";} ’;;s/\s*//g;; eval ; eval("seek \040 DATA ,0 ,0;"); undef$ /; $_=<DATA >;s/\s*//g;( );;s

;^.*_;;; map{ eval " print \" $_ \"" ;}/.{4}/ g; __DATA__ \124\1 50\145\040\165\163\145\040\157\1 46\040\1 41\0

40\143\141 \155\145\1 54\040\1 51\155\ 141\147\145\0 40\151\156 \040\141 \163\16 3\

157\143\ 151\141\16 4\151\1 57\156\040\167 \151\164\1 50\040\ 120\145\162\ 154\040\15 1\163\ 040\141\040\1 64\162\1 41\144 \145\155\14 1\162\ 153\04 0\157

\146\ 040\11 7\047\ 122\145\15 1\154\1 54\171 \040\046\ 012\101\16 3\163\15 7\143\15 1\141\16 4\145\163 \054

\040 \111\156\14 3\056\040\ 125\163\145\14 4\040\167\1 51\164\1 50\0 40\160\

145\162 \155\151\163\163 \151\1

57\156\056

Tuukka HaapasaloScripting languages: Perl and PHP

Page 6: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Black PerlBEFOREHAND : close door , each window & exit ; wait until time .

open spellbook , study , read (scan , select , tell us );write it , print the hex while each watches ,

reverse its length , write again ;kill spiders , pop them , chop , split , kill them.

unlink arms , shift , wait & listen (listening , wait ),sort the flock (then , warn the " goats " & kill the " sheep ");

kill them , dump qualms , shift moralities ,values aside , each one;

die sheep ! die to reverse the systemyou accept (reject , respect );

next step ,kill the next sacrifice , each sacrifice ,

wait , redo ritual until "all the spirits are pleased ";do it ("as they say").

do it (* everyone *** must *** participate *** in *** forbidden **s*e*x*).return last victim ; package body;

exit crypt (time , times & "half a time") & close it ,select ( quickly ) & warn your next victim ;

AFTERWORDS : tell nobody .wait , wait until time ;

wait until next year , next decade ;sleep , sleep , die yourself ,

die at last

Tuukka HaapasaloScripting languages: Perl and PHP

Page 7: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Introduction

Introduction

Perl was originally developed by Larry Wall, a linguist workingas a systems administrator for NASA [11].Perl is based on languages including C, shell scripting (sh),AWK, and sed (and Pascal, and BASIC|PLUS, . . . ).Initial purpose was to be a replacement for an overtaxed awk.Wall used Perl as a general-purpose Unix scripting languageto make report processing easier.

Perl slogans [5]

There’s more than one way to do it.Perl makes easy jobs easy, and the hard jobs possible.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 8: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Introduction

Usage of Perl

Used for easy manipulation of text files, graphicsprogramming, system administration, network programming,applications that require database access and CGIprogramming on the Web [11].Nicknamed "the Swiss Army chainsaw of programminglanguages" due to its flexibility and adaptability.See an introduction to Perl by Stotts [9].

Tuukka HaapasaloScripting languages: Perl and PHP

Page 9: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Introduction

Etymology

Etymology

Perl was originally named Pearl, after the Parable of the Pearlfrom the Gospel of Matthew. [11]Name arbitrarily chosen for its positive connotations.Renamed to Perl to differentiate from the existingprogramming language PEARL.Common acronyms coined afterwards (from Perl man pages):

Practical Extraction and Report LanguagePathologically Eclectic Rubbish Lister

Tuukka HaapasaloScripting languages: Perl and PHP

Page 10: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

History of Perl [2]1987 Perl 1.000 released.1988 Perl 2.000 released.1989 Perl 3.000 released, first public Perl tutorial.1990 Convex (computer vendor) includes Perl as part of its standard

OS distribution.1991 Perl 4.000 released, Programming Perl (1st edition) published.1992 First release of MacPerl.1994 Perl 5.000 released.1995 CPAN (Comprehensive Perl Archive Network) introduced to

the Perl community.1996 Doug MacEachern introduces mod_perl, which embeds a Perl

interpreter into an Apache module.1998 The movie Sphere is released featuring a small snippet of code

from the Perl FAQ.

Full release history found in Perl Programming Documentation [1].Tuukka HaapasaloScripting languages: Perl and PHP

Page 11: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Important peopleLarry Wall, author of Perl, a linguist working as systemsadministrator for NASA. Author also of rn (Usenet client) andpatch. Co-author of Programming Perl (the Camel book).Randal Schwartz a.k.a. merlyn, author of most Perl programmingbooks. Author of the Schwartzian transform. Popularized the Justanother Perl hacker signatures.Jarkko Hietaniemi, creator and self-appointed master librarian ofCPAN, author of several Perl modules, maintainer of Perl.

Schwartzian transform [13]

@sorted = map { $_->[0] }sort { $a->[1] cmp $b->[1] }map { [$_, foo($_)] }

@unsorted;

Tuukka HaapasaloScripting languages: Perl and PHP

Page 12: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Perl 1.000, 1987DESCRIPTIONPerl is a interpreted language optimized for scanning arbi-trary text files, extracting information from those textfiles, and printing reports based on that information. It’salso a good language for many system management tasks. Thelanguage is intended to be practical (easy to use, effi-cient, complete) rather than beautiful (tiny, elegant,minimal). It combines (in the author’s opinion, anyway)some of the best features of C, sed, awk, and sh, so peoplefamiliar with those languages should have little difficultywith it. (Language historians will also note some vestigesof csh, Pascal, and even BASIC|PLUS.) Expression syntaxcorresponds quite closely to C expression syntax. If youhave a problem that would ordinarily use sed or awk or sh,but it exceeds their capabilities or must run a little fas-ter, and you don’t want to write the silly thing in C, thenperl may be for you. There are also translators to turnyour sed and awk scripts into perl scripts. OK, enoughhype.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 13: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Perl 2.000, 1988

Recursive subroutine calls.Local variables in blocks, subroutines and evals.The manual is now not lying when it says that perl isgenerally faster than sed. I hope. -- Elaine Ashton [2]Assignments can function as lvalues, so you can say things like($HOST = $host) =~ tr/a-z/A-Z/; ($obj = $src) =~s/\.c$/.o/;

Tuukka HaapasaloScripting languages: Perl and PHP

Page 14: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Perl 3.000, 1989

Correct binary data handling, functions to pack and unpackbinary structures into arrays or lists.Passing values to subroutines by reference.List chopping.New functions: mkdir and rmdir, getppid, getpgrp andsetpgrp, getpriority and setpriority, chroot, ioctland fcntl, . . .

Tuukka HaapasaloScripting languages: Perl and PHP

Page 15: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Perl 4.000, 1991

No major changes in the language.Programming Perl released and became the de facto standardfor the language.Perl version number changed to identify the versiondocumented by the book.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 16: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Perl 5.000, 1994

Complete rewrite of Perl.Objects.Lexical scoping available via my. eval can see the currentlexical variables.Package delimiter changed from ’ to ::.New functions: abs(), chr(), uc(), ucfirst(), lc(),lcfirst(), chomp(), glob().Pattern matching modifiers for single/multiline: m and s.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 17: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

CPAN [4]

Archive of over 18000 Perl software modules anddocumentation, most free and open-source.CPAN means either the archive itself or the automatedsoftware installer.It is said that half of Perl’s power is in the CPAN.Exhaustive standard software repository for the language, mostother languages do not have as exhaustive standard libraries.Includes also joke distributions such as the Acme::don’tmodule that adds a don’t function which doesn’t run codegiven to it.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 18: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Perl 5.x and onwards [11]

Perl 5.6, 2000 64-bit support, Unicode strings, large files, ourkeyword. Version numbering changed, 5.x isdevelopment version if x is odd, stable if x is even.

Perl 5.8, 2002 Improved Unicode, new I/O implementation, newthread implementation, better numeric accuracy.

Perl 5.10, 2007 20th anniversary of Perl. New switch statement(given / where), regexp updates, smart operator ~~.

Perl 6 No promise of release date. Next major release ofdevelopment, Rakudo Perl, is expected in 2010. Perl6 will differ fundamentally from Perl 5, but the intentis to “keep Perl 6 Perl”.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 19: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Syntax

Perl SyntaxPerl examples

use strict ;my $a = ’Three \\\ ’s: "\\\\\" ’;my $b = 20\ _000\_000;my $c = 2.5e -3;

$b <=> $c;$a cmp ’Two \\\ ’s: "\\\\" ’;

my $greet = "Hi! ";my $name = "Paul";my $longGreet = $greet x 3;my $hi = $longGreet . $name . ", " . $greet ;my $sentence = "${name}’s dog weighs between more than $c pounds .";

($v3 , $v4) = upcase ($v1 , $v2 ); # this doesn ’t change $v1 and $v2sub upcase {

return unless defined wantarray ; # void context , do nothingmy @parms = @_;for ( @parms ) { tr/a-z/A-Z/ }return wantarray ? @parms : $parms [0];

}

Tuukka HaapasaloScripting languages: Perl and PHP

Page 20: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Syntax

ArraysArrays may only contain scalar contents.

Array examplesuse strict ;my @a = (" three ", "word", " array ");my @b = qw/ three word array /;my @c = (@a , "and", @b );

$a [1] == "word";$#b == 2; # Index of last entry$#a = 1; # Crops the length of the a array to 2$#c = -1; # Clears the c array@a = (); # Also clears the array

@a = (1 .. 100);@b = (’A’ .. ’Z’);@c = (’01 ’ .. ’31 ’);

@b = @a [0 .. 4]; # 5 first elements of a@c = @a[0, 2, 10]; # Pick some elements

Tuukka HaapasaloScripting languages: Perl and PHP

Page 21: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Syntax

Hashes

Again, hashes may only contain scalar contents.

Hash examplesuse strict ;my % table ;$table {’schmoe ’} = ’joe ’;$table {7.5} = 2.6;

Tuukka HaapasaloScripting languages: Perl and PHP

Page 22: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Syntax

Regular ExpressionsRegexp examples

# Pattern matchingif ( $currentLine =~ m/ sought_text /) { ... }

# String selection$string =~ m/ whatever ( sought_text ) whatever2 /;$soughtText = $1;

# String replacement$string =~ s/ originaltext / newtext /;

# Letter -by - letter translation$string =~ tr /[a,e,i,o,u,y]/[A,E,I,O,U,Y]/;

Operators in regular expressions:?PAT? q/STR/ or qq/STR/m/PAT/cgimosx or /PAT/cgimosx qr/STR/imosxs/PAT/REPLACE/egimosx qx/STR/ or ‘STR‘tr/SEARCH/REPLACE/cds qw/STR/ = split(’ ’, q/STR/);y/SEARCH/REPLACE/cds

Tuukka HaapasaloScripting languages: Perl and PHP

Page 23: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Syntax

Other features [1]

require - require a certain version of Perl, or require that amodule is imported.overload - overload Perl operators.bless - tells that the thingy (sic.) referenced by theargument is now an object.Garbage collection without cycle detection.Compilation can be affected by run-time code executed duringthe compile phase.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 24: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Syntax

Objects in Perl [1]

Perl classes are simply packages.Objects of the class need to be blessed, for example by aconstructor method.No specific new constructor, just use whatever method nameseems appropriate.Inheritance can be implemented by the @ISA array which tellswhere to look if a method can’t be found from the package.Class methods are normal subroutines. Invocation via syntax$var->method().

Tuukka HaapasaloScripting languages: Perl and PHP

Page 25: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

PHP

Tuukka HaapasaloScripting languages: Perl and PHP

Page 26: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

Introduction

Introduction

Main developers

Rasmus Lerdorf, a Danish-Greenlandic programmer, createdthe first version of PHP (started 1994, released 1995).Currently works at Yahoo!Zeev Suraski and Andi Gutmans, two Israeli programmers,rewrote parser for PHP/FI 2 in 1997, released as PHP 3 in1998. Both currently work at Zend Technologies in Tel Aviv,Israel.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 27: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

History

PHP [7, 8, 12]

1994 - Personal Home Page Tools (PHP Tools), personal use. [RL]1995 - PHP / Form Interpreter (PHP/FI). First release. [RL]1997 - PHP/FI 2. [RL]1998 - PHP 3.0, renamed to PHP: HyperText Preprocessor. [ZS&AG]2000 - PHP 4.0. [ZS&AG]2004 - PHP 5.0. [ZS&AG]Future - PHP 6.0. [ZS&AG]

Competitors:ASP released as an add-on to IIS via WinNT 4.0 Option Pack in 1998.JSP 1.0 specification released in 1999 as Java’s answer to PHP and ASP.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 28: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Personal Home Page Tools

Created by Rasmus Lerdorf in 1994.Written in C to replace a set of Perl scripts for showing hison-line résumé and for tracking access to the web site.For personal use, not released for public.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 29: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Personal Home Page / Form Interpreter

Created by Rasmus Lerdorf.First release of PHP in 1995.PHP Tools merged with Form Interpreter, called PHP/FI.Communication with databases.Could be used to create dynamic web pages.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 30: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Example code

PHP/FI example [6]<!-- getenv HTTP_USER_AGENT --><!-- ifsubstr $exec_result Mozilla -->Hey , you are using Netscape !<p><!--endif -->

<!--sql database select * from table where user=’$username ’-->

<!-- ifless $numentries 1-->Sorry , that record does not exist <p><!-- endif exit -->

You have <!-- $index :0--> credits left in your account .<p>

<!-- include /text/ footer .html -->

Tuukka HaapasaloScripting languages: Perl and PHP

Page 31: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

PHP/FI 2.0

Created by Rasmus Lerdorf [8] and several other people.Re-write of the PHP/FI C implementation.Released in 1997.Several thousand users, installed on 50000 web sites, approx.1 % of Internet domains.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 32: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

Example code

PHP/FI 2.0 example [6]<?

$name = "bob";$db = "db";$result = msql($db ," select * from table where firstname =’ $name ’");$num = msql_numrows ( $result );echo "$num records found !<p>";$i =0;while ($i <$num );

echo msql_result ($result ,$i ," fullname ");echo "<br >";echo msql_result ($result ,$i ," address ");echo "<br >";$i ++;

endwhile ;>

Tuukka HaapasaloScripting languages: Perl and PHP

Page 33: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

PHP 3.0

A complete rewrite by Andi Gutmans and Zeev Suraski.PHP/FI 2.0 was too underpowered for the eCommerceapplication Gutmans and Suraski were building.Released in 1998, called PHP: HyperText Preprocessor (PHP).Strong extensibility features.Object-oriented syntax.First successful release of PHP.Tens of thousands of users, installed on hundreds ofthousands of web sites, approx. 10 % of Internet domains.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 34: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

PHP 4.0

Again, a rewrite by Gutmans and Suraski and a developmentteam of dozens of developers.The core is called the Zend Engine (from Zeev and Andi).Gutmans and Suraski found Zend Technologies.Support for more web servers, HTTP sessions, outputbuffering, secure user input handling, references, booleantype, PCRE library included.Improved speed and reliability.Used by hundreds of thousands of developers, installed onseveral million sites, approx. 20 % of Internet domains.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 35: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

PHP 5.0

Core is Zend Engine 2.0.Released in 2004.New object model, embedded SQLite, exception handling(try . . . catch), integrated SOAP support, better XML tools,iterators. . .

Tuukka HaapasaloScripting languages: Perl and PHP

Page 36: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

PHP 5.0 example [6]<?phpclass db {

protected static $dbh = false ;function connect () {

self :: $dbh = new PDO(’mysql :host= localhost ; dbname =test ’,’user ’,’pass ’);self :: $dbh -> setAttribute (PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION );

}}class items extends db {

function load( $name ) {if (! self :: $dbh) $this -> connect ();try {

if (! self :: $dbh) $this -> connect ();$stmt = self :: $dbh -> prepare (" SELECT * FROM items WHERE firstname =: name

ORDER by ctime desc");$ret = $stmt -> execute ( array (’name ’=> $name ));

} catch ( PDOException $e) { die($e -> getMessage ()); }return $ret;

}}$db = new items ; $result = $db ->load("bob");foreach ($result -> fetch (PDO :: FETCH_ASSOC ) as $row) {

echo <<<EOB{$row[’fullname ’]}<br />EOB;

} ?>

Tuukka HaapasaloScripting languages: Perl and PHP

Page 37: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

History

PHP 6.0

In development since 2006.Feature changes:

Native Unicode supportMagic quotes removedGlobal registering removedSafe mode removedCommand-line scripting

Tuukka HaapasaloScripting languages: Perl and PHP

Page 38: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

References I[1] J. Allen.

Perl programming documentation, 2009.http://perldoc.perl.org/. Referenced on 9.11.2009.

[2] E. Ashton.The timeline of perl and its culture, 2001.http://history.perl.org/PerlTimeline.html. Referenced on 9.11.2009.

[3] DedaSys LLC.Programming language popularity, Nov 2009.http://langpop.com/. Referenced on 18.11.2009.

[4] J. Hietaniemi.Cpan - comprehensive perl archive network, 2009.http://www.cpan.org/. Referenced on 18.11.2009.

[5] B. M. Kuhn.Picking Up Perl.Internet, Jan 2001.http://www.faqs.org/docs/pperl/. Referenced on 9.11.2009.

[6] R. Lerdorf.Performance and security, Mar 2007.http://talks.php.net/show/oscms07/. Referenced on 19.11.2009.

[7] NuSphere Corporation.The history of PHP, 2009.http://www.nusphere.com/php/php_history.htm. Referenced on 18.11.2009.

Tuukka HaapasaloScripting languages: Perl and PHP

Page 39: Scripting languages: Perl and PHP - Aalto · Language Popularity Perl PHPReferences Scripting languages: Perl and PHP TuukkaHaapasalo December1,2009 Tuukka Haapasalo Scripting languages:

Language Popularity Perl PHP References

References II

[8] PHP Documentation Group.PHP manual, 2009.http://www.php.net/manual/. Referenced on 18.11.2009.

[9] D. Stotts.The Perl scripting language, Dec 2002.http://rockfish-cs.cs.unc.edu/COMP144/IEPerl.pdf. Referenced on 18.11.2009.

[10] Tiobe Software.TIOBE programming community index for November 2009, Nov 2009.http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html. Referenced on 18.11.2009.

[11] Wikipedia.Perl, 2009.http://en.wikipedia.org/wiki/Perl. Referenced on 9.11.2009.

[12] Wikipedia.PHP, 2009.http://en.wikipedia.org/wiki/PHP. Referenced on 9.11.2009.

[13] Wikipedia.Schwartzian transform, 2009.http://en.wikipedia.org/wiki/Schwartzian_transform. Referenced on 18.11.2009.

Tuukka HaapasaloScripting languages: Perl and PHP