Comparing Python, Perl, and PHP: Origins, Features, and Tools

introduction to script languages such as python n.w
1 / 18
Embed
Share

Explore the origins of Python, Perl, and PHP script languages, compare their features such as scripting vs. compiled languages, and discover popular interpreters and IDEs for Python, Perl, and PHP with demonstrations included.

  • Python
  • Perl
  • PHP
  • Scripting
  • Programming

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. INTRODUCTION TO SCRIPT LANGUAGES SUCH AS PYTHON, PERL, PHP MORRIS LAW, SCID MARCH 7, 2018

  2. PROGRAMMING LANGUAGES SCRIPTING VS COMPILED LANGUAGES Scripting Can run without compilation Compiled Need to compile to machine code before running C/C++, Fortran,Pascal, Java Optimized and run faster, Source code protected Codes are compiled to executables using compiler Feature Examples Advantage Python, Perl, PHP,Ruby, Javascript Easy to understand and extend Portable Use an interpreter to understand and run the code on-the-fly Running and Debugging model

  3. BRIEF COMPARISONS ON 3Ps Python Guido van Rossum 1989 ReplacingABC Machine Learning 2.7.14, 3.6.4 www.python.org Anaconda3 (64bit), Python 3.6.4 Perl Larry Wall 1987 Produce reports Regular Expressions 5.26.1 www.perl.org DWIMperl 5.14.2.1(v7) Strawberry PERL 5.26.1 ActiveState PERL 5.26.1 PHP Rasmus Lerdorf 1994 Form interpretation Web Programming 5.6.34, 7.0.28, 7.1.14, 7.2.3 www.php.net PHP 5.6.34 PHP 7.2.3 Written by Written in Written for Expert in Current versions Website Software installable on Windows

  4. 3Ps -- ORIGINS OF THEIR NAMES Python: Name comes from the British comedy series, Monty Python s Flying Circus Perl : Short form of Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister PHP : Hypertext Preprocessor

  5. INTERPRETER / IDE FOR PYTHON, PERL AND PHP Spyder in Anaconda3 IDLE for Python 3.6.4 Padre, the PERL IDE PHPdesigner 8, PHPstorm for PHP (Not free)

  6. DEMONSTRATIONS Using Spyder and IDLE for Python Using Padre: PERL IDE Download, install and run PHP 5.6.34 Running given Python, PERL and PHP examples with Command Line Interface

  7. RUNNING BASICS IN PYTHON, PERLAND PHP Python helloworld.py python helloworld.py PERL helloworld.pl perl helloworld.pl $i = range(1:5); PHP helloworld.php php helloworld.php $n = 10; File name/extensions Command line running Variable declaration spouse= ['may', 'peter']; a,b,c = 1, 2, 4; number string " " list [ ] tuple ( ) dictionary { } Data type supported string integer / float boolean array object array ( ) @array=(); hash { } %lookup={} sequence [ ]

  8. SCRIPTS WRITTEN IN PYTHON, PERLAND PHP Python print("HelloWorld!"); PERL print "HelloWorld!\n"; PHP print "HelloWorld!"; HelloWorld Fibonacci sequence def printFibo(n): first = 0; second = 1; sub printFibo { my ($n) = @_; my $first = 0; my $second = 1; <?php function printFibo($n) { $first = 0; $second = 1; print("Fibonacci Series"); print(first, second, end=' '); print "Fibonacci Series\n"; print $first .' '. $second . ' '; for ($i=2; $i<$n; $i++) { $third = $first + $second; print $third . ' '; echo "Fibonacci Series \n"; echo $first.' '.$second.' '; for($i=2; $i<=$n; $i++){ $third = $first + $second; echo $third.' '; $first = $second; $second = $third; } for i in range(2,n+1): third = first + second; print(third, end=' '); first=second; second=third; $first=$second; $second=$third; # Function call to print Fibonacci series up to 10 numbers. } } } printFibo(10); # Function call to print Fibonacci series up to 10 numbers. /* Function call to print Fibonacci series upto 6 numbers. */ printFibo(10); printFibo(10); ?>

  9. SCRIPTS WRITTEN IN PYTHON, PERLAND PHP Python PERL PHP Writing functions def fibo(n): if n < 2: sub fibo { my ($rec) = @_; return 0 if $rec == 0; return 1 if $rec == 1; return fibo($rec-1) + fibo($rec-2); } <?php function fibo($n) { if (($n==0) or ($n==1)) return $n; else return fibo($n-2)+fibo($n-1); } echo fibo(10); return n return fibo(n-2) + fibo(n-1) print(fibo(20)); print fibo(20); use strict use warnings use GD::Simple packages/modul es inclusion import math import numpy import matplotlib

  10. MORE EXAMPLES IN PYTHON PYDATATYPE.PY #!/usr/bin/python # String retrieval # This example scripts aims to introduce data types supported by Python str = 'Hello World!' # Ordinary data type, integer, float, string print(str) # Prints complete string counter = 100 # An integer assignment print(str[2:5]) # Prints characters starting from 3rd to 5th miles = 1000.0 # A floating point print("My name is %s and weight is %d kg!" % ('Zara', 21)) name = "John" # A string # List operations # Python version 2 use 'print' without () list = [ 'abcd', 786 , 2.23, 'john', 70.2 ] # print counter,miles, name # version 2 syntax tinylist = [123, 'john'] # Python version 3 change to use brackets, print(a,b,c) print(list) # Prints complete list print(counter,miles,name) print(list[0]) # Prints first element of the list # multiple assignment print(len(list)) # Prints elements starting from 2nd till 3rd a,b,c = 1,2,"john"; print(tinylist * 2) # Prints list two times print(b,c); list.append('john') print(list.count('john')) #return count of how many time 'john' occurs

  11. MORE EXAMPLES IN PYTHON PYDATATYPE.PY (CONT.) # Tuple operations # Dictionary tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} tinytuple = (123, 'john') print("dict['Name']: ", dict['Name']) print("dict['Age']: ", dict['Age']) print(tuple) # Prints complete list dict['Age'] = 8; # update existing entry print(tuple[0]) # Prints first element of the list dict['School'] = "DBS"; # Add new entry print(tuple[2:]) # Prints elements starting from 3rd element print("dict['Age']: ", dict['Age']) print(tinytuple * 2) # Prints list two times print("dict['School']: ", dict['School']) print(tuple + tinytuple) # Prints concatenated lists del dict['Name']; # remove entry with key 'Name'

  12. MORE EXAMPLES IN PYTHON PYFUNCTIONS.PY #!/usr/bin/python # the 2nd function, use math.pi to calculate area and circumference of a circle import math def circle(r) : # following are 2 other ways to call import area = m.pi * r * r; #import math as m circum = m.pi * r * 2; #from math import * return area, circum; total = 0; # This is global variable. # the 3rd function is an anonymous (lambda) function # 3 function definitions are here product = lambda arg1, arg2: arg1 * arg2; # the 1st function: sum returning a result r=5; def sum( arg1, arg2 ): a,c = circle(r); # Add both the parameters and return them." # Now you can call sum and product as a function total = arg1 + arg2; # Here total is local variable. print("The area and circumference of the circle with radius %d is %f and %f respectively" % (r,a,c)); print("Inside the function local total : ", total) return total; print("Value of total : ", sum( 10, 20 )) print("Value of product : ", product( 30, 20 )) print("Outside the function global total : ", total)

  13. MORE EXAMPLES IN PYTHON PYIMNUM.PY import numpy as np a = [1,3,5]; b = [2,4,6]; na = np.array([1,3,5]); nb = np.array([2,4,6]); c,d = a+b, na + nb; print(c); print(d); import matplotlib.pyplot as plt # evenly simpled time at 200ms intervals t = np.arange(0., 5., 0.2) # red dashes, blue squares and green triangles plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') plt.show()

  14. MORE EXAMPLES IN PYTHON PYIMNUM.PY (CONT) from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D X = np.arange(-5, 5, 0.25) Y = np.arange(-5, 5, 0.25) X, Y = np.meshgrid(X, Y) R = np.sqrt(X**2 + Y**2) Z = np.cos(R) fig = plt.figure() ax = Axes3D(fig) ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.viridis) plt.show()

  15. SELF LEARNING LINKS Python www.learnpython.org https://www.tutorialspoint.com/python/index.htm https://matplotlib.org/gallery/index.html PERL http://www.learn-perl.org/ https://learn.perl.org/tutorials/ PHP http://www.learn-php.org https://www.w3schools.com/php/

  16. THANKS MORRIS LAW, SCID, HKBU MORRIS@HKBU.EDU.HK

  17. EVALUATION FORM HTTPS://GOO.GL/FORMS/880NY3KZ9H7AY7R32

Related


More Related Content