python and perl


Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

python and perl

  1. 1. Python<br />and<br />perL<br />Mara Angelica M. Refraccion<br />BSCS41A<br />
  2. 2. Python<br />
  3. 3.
  4. 4. <ul><li>An interpreted, general-purpose high level programming language whose design philosophy emphasizes code readability.
  5. 5. Very clear, readable syntax
  6. 6. Intuitive object orientation
  7. 7. Natural expression of procedural code
  8. 8. Full modularity, supporting hierarchical packages</li></li></ul><li><ul><li>Exception-based error handling
  9. 9. Very high level dynamic data types
  10. 10. Extensive standard libraries and third party modules for virtually every task.
  11. 11. Extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython)
  12. 12. Embeddable within applications as a scripting interface</li></li></ul><li>History<br /><ul><li>Python was conceived in the late 1980s and its implementation was started in December 1989
  13. 13. Guido van Rossum (Python's principal author, and his continuing central role in deciding the direction of Python is reflected in the title given to him by the Python community, Benevolent Dictator for life(BDFL))
  14. 14. CWI in the Netherlands  </li></li></ul><li><ul><li>Python 2.0 was released on 16 October 2000, with many major new features including a full garbage collector
  15. 15.  Python 3.0 (also known as Python 3000 or py3k was released on 3 December 2008 after a long period of testing.
  16. 16. Python has twice been awarded as TIOBE Programming Language of the Year (2007, 2010), which is given to the language with the greatest growth in popularity over the course of the year (as measured by the TIOBE index)</li></li></ul><li>
  17. 17.
  18. 18.
  19. 19.
  20. 20.
  21. 21.
  22. 22.
  23. 23. Basic Syntax<br /># # comment <br /> <br /> # line continuation <br /> <br />; # statement separator (like C) <br />None # NULL <br /> <br />not # logical/boolean not returns True/False <br />== != < > <= >= # equality, relational <br /> <br />is # object identity <br />is not<br /> <br />** # power (x^y) <br /> <br />// # floor division (truncates to integer) <br />
  24. 24. float(123) float('123.0') # convert integer/string to float <br />int(1.5) # convert to integer (truncate) <br />bool(x) # convert to boolean<br />hex(15) # convert to string in hex format <br />int('101',2) # convert to int from binary number in string <br />
  25. 25.
  26. 26.
  27. 27.
  28. 28.
  29. 29.
  30. 30.
  31. 31.
  32. 32.
  33. 33.
  34. 34.
  35. 35.
  36. 36.
  37. 37.
  38. 38. Basis Reserved words<br /><ul><li>Expression statements are used (mostly interactively) to compute and write a value, or (usually) to call a procedure (a function that returns no meaningful result; in Python, procedures return the value None).
  39. 39. Assert statements are a convenient way to insert debugging assertions into a program.
  40. 40. Pass is a null operation — when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed.</li></li></ul><li><ul><li>Deletion of a target list recursively deletes each target, from left to right.
  41. 41. Print evaluates each expression in turn and writes the resulting object to standard output .
  42. 42. Break may only occur syntactically nested in a for or whileloop, but not nested in a function or class definition within that loop.</li></li></ul><li><ul><li>Continue may only occur syntactically nested in a for or while loop, but not nested in a function or class definition or finally clause within that loop. It continues with the next cycle of the nearest enclosing loop.
  43. 43. Import statements are executed in two steps: (1) find a module, and initialize it if necessary; (2) define a name or names in the local namespace (of the scope where the import statement occurs).
  44. 44. The global statement is a declaration which holds for the entire current code block. </li></li></ul><li>Python Application<br /><ul><li>Web development</li></ul> *Extensive support for HTML and XML.<br /> *E-mail processing.<br /> *Processing RSS feeds.<br /> *Support for many other Internet protocols.<br /><ul><li>Database Access</li></ul> *MySQL, Oracle, MS SQL Server, PostgreSQL, SybODBC, and others are available for free download.<br /><ul><li>Scientific and Numeric</li></ul> *Bioinformatics<br /> *Python course in Bioinformatics<br /> *Physics<br />
  45. 45. <ul><li>Education
  46. 46. Network Programming</li></ul> *Easy-to-use socket interface<br /> *Twisted Python, a framework for asynchronous network programming.<br /><ul><li>Software Development
  47. 47. Game and 3D Graphics</li></li></ul><li>Perl<br />
  48. 48. <ul><li>Perl is a interpreted and dynamic programming language
  49. 49. Perl is stable and cross-platform programming language.
  50. 50. It has inherited the best features from C, Basic and other programming languages.
  51. 51. Perl supports Unicode character encoding for foreign letters.</li></li></ul><li><ul><li>Other interesting feature is, it supports both procedural and object oriented programming.
  52. 52. Perl is extensible and can be integrated with C and C++.
  53. 53. Perl is best known for powerful text processing engine.
  54. 54. Perlwas known to be the most popular web programming language until PHP supercedes it.</li></li></ul><li>History<br /><ul><li>Perl was initially developed by Larry Wall in 1987.
  55. 55. Perl is a open source software licensed under GNU public license
  56. 56. It was made as a unix scripting language for reporting process.</li></li></ul><li><ul><li>Perl is also called as the swiss army chainsaw of programming languages due to its flexible and adaptable nature.
  57. 57. Perl  2 released in 1988 with better and improved regular exprssion engine
  58. 58. In 1989, perl 3 was released with added feature of handling binary data streams.</li></li></ul><li><ul><li>In 1991, perl reference documentations has been published, it is also called as ‘Camel Book’ and version was renamed to Perl 4.
  59. 59. Perl interpreter was completely rewritten and released in 1994 as Perl verison 5.
  60. 60. Perl 5.x version is the most widely used as of now</li></li></ul><li>Comparison with Other Programming Languages<br />C/C++<br /><ul><li>Perl is written in the C programming language.
  61. 61. C/C++ programs are platform dependent.</li></li></ul><li><ul><li>C/C++ is a very structured language, its syntax is not as exible as scripting languages such as Perl.
  62. 62. C/C++ version requires more lines of code compared with Perl.
  63. 63. improperly written C/C++ programs are vulnerable to memory leak problems</li></li></ul><li>PHP<br /><ul><li>Allows embedding of inline PHP code inside HTML documents that makes it very convenient to embed small snippets of PHP code.
  64. 64. PHP supports the object-oriented paradigm, most of its functionalities are provided through functions.</li></li></ul><li>Java/JSP<br /><ul><li>Java syntax is very structured and thus are not as fexibleas scripting languages like Perl.
  65. 65. Java itself is not just an interpreter, it is a virtual machine over which programmers are totally abstracted from the underlying operating system platforms</li></li></ul><li>How A Perl Program Is Executed<br />Preprocessing<br />An optional preprocessing stage transforms the source file to the final form.<br />Tokenizing <br />The source le is broken down into tokens. This process is called tokenization (or Lexical analysis). Whitespaces are removed. Token is the basic unit that makes up a statement. By tokenizing the input parsing is becoming easier because all further processing are carried out on tokens,independent of whitespace.<br />
  66. 66. Parsing & Optimization (Compilation) <br />Parsing involves checks to ensure the program being executed conforms to the language specication and builds a parse tree internally which describes the program in terms of microoperations internal to Perl (opcode).<br />
  67. 67. Literals<br /><ul><li>Numbers (integers and decimals)</li></ul> * In Perl, integers can be expressed in decimal (base 10), hexadecimal (base 16) or octal (base 8) notation.<br /> * Integers cannot be delimited by commas or spaces like 10,203,469 or 20 300.<br /> * Exponents (base 10) can also be specied by appending the letter .”e”<br />and the exponent to the real number portion. e.g. 2e3 is equivalent to 2 x 103 = 2000.<br />
  68. 68. <ul><li>Strings</li></ul> * A string is a sequence of characters enclosed (delimited) by either double quotes (.) or single quotes<br />(').<br /> * Escape characters are usually put inside<br />double-quoted strings.<br />
  69. 69.
  70. 70.
  71. 71. <ul><li>scalar variable</li></ul>* Is a named entity representing a piece of scalar data of which the<br />content can be modied throughout its lifetime.<br /> * all variables are global.<br /><ul><li>Array</li></ul>* a named entity representing a list of scalar data, with each item assigned an index.<br /> * An array can be empty, that is, containing no elements (called a null array).<br />
  72. 72. <ul><li>Hash </li></ul> * Is a special data structure. It is similar to an array except that the index is not an integer, a string is used for indexing, and is known as a key. The key is conceptually like a tag which is attached to the corresponding value. The key and the value forms a pair (key-value pair).<br />
  73. 73. Arithmetic operators manipulate on numeric scalar data. Perl can evaluate an arithmetic expression, in a way similar to our daily-life mathematics.<br />Operator Description<br />+ Addition operator<br />- Subtraction operator<br />* Multiplication operator<br />/ Division operator<br />% Modulus operator<br />+ Positive sign<br />- Negative sign<br />++ Autoincrement operator<br />-- Autodecrement operator<br />** Exponentiation operator<br />
  74. 74. Comparison operators are used to compare two pieces of scalar data, e.g. alphabetically or numerically and returns a Boolean value. <br />In Perl, there are two sets of comparison operators. The rst set compares the operands numerically:<br />Operator Description<br />< less than<br />> greater than<br /><= less than or equal to<br />>= greater than or equal to<br /><=> general comparison<br />
  75. 75. The second set compares the operands stringwise:<br />Operator Description<br />lt less than<br />gt greater than<br />le less than or equal to<br />ge greater than or equal to<br />cmp general comparison<br />
  76. 76. Equality operators compares two pieces of scalar data and returns if their values are identical. They may be considered special cases of comparison operators.<br />Operator Description<br />== equal (numeric comparison)<br />!= not equal (numeric comparison)<br />eq equal (stringwise comparison)<br />ne not equal (stringwise comparison)<br />
  77. 77. Bitwise operators provide programmers with the capability of performing bitwise calculations.<br />Operator Description<br /><< Binary shift left<br />>> Binary shift right<br />& Bitwise AND<br />| Bitwise OR<br />ˆ Bitwise XOR<br />~ Bitwise NOT<br />
  78. 78. Logical operators can be used to do some Boolean logic calculations.<br />Operator Description<br />|| or Logical OR<br />&& and Logical AND<br />! not Logical NOT, i.e. negation<br />xor Logical XOR.Exclusive OR<br />
  79. 79. test1 test2 and && or || xor<br />true true true true false<br />true false false true true<br />false true false true true<br />false false false false false<br /> Test not !<br /> true false<br /> false true<br />Table 4.1: Truth table of various Perl logical operators<br />
  80. 80. String manipulation operators manipulate on strings.<br />Operator Description<br />x String repetition operator<br />. String concatenation operator<br />