1 / 20

Introduction to Perl Programming

Explore the basics of Perl programming, including statements, blocks, variables, literals, and operators. Learn how to write Perl scripts and practice essential commands.

houser
Download Presentation

Introduction to Perl Programming

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dr. Zhixin Zhao Chapter 4Perl programming Section 1: Perl introduction, Perl statements and blocks

  2. Operating System • The most important program that runs on a computer. • Operating systems perform basic tasks, such as recognizing input from the keyboard, sending output to the screen, keeping track of files on the disk, and controlling peripheral devices such as disk drives and printers. 1. Perl introduction

  3. Windows, Mac, Unix and Linux

  4. Perl is the abbreviation of Practical Extraction and Reporting Language, and it is designed and developed by Larry Wall on December 18, 1987. It is especially designed for processing text.

  5. Integrated Development Environment (IDE) • a programming environment integrated into a software application that provides a GUI builder, a text or code editor, a compiler and/or interpreter and a debugger. Komodo 3.5 www.activestate.com

  6. Variable and Values • Symbolic representation denoting a quantity or expression.

  7. In computer source code, a variable name is one way to bind a variable to a memory location; the corresponding value is stored as a data object in that location so that the object can be accessed and manipulated later via the variable's name.

  8. Mechanics of Writing Perl Programs • A Perl program is just a text file. Use any text (programmer's) editor. Windows: Notepad, Wordpad Linux: gedit, vi, emacs • By convention, Perl program files end with the extension .pl. #!/usr/bin/perl # file: time.pl $time = localtime; print "The time is now $time\n"; • perl time.pl

  9. A Perl script consists of statements and comments. • Each statement is a command that is recognized by the Perl interpreter and executed. • Statements are terminated by the semicolon character (;). #!/usr/bin/perl # file: getseq.pl print “Enter your seq …\n”; $Seq=<STDIN>; print “Your input=$Seq\n"; 2. Perl statements and blocks

  10. Block: A group of statements, using curly braces. • You can execute blocks conditionally. #!/usr/bin/perl # file: enzyme.pl $EcoRI = ‘GAATTC’; $Seq=<STDIN>; If ($Seq=~$EcoRI)‏ { print “Your seq=$Seq\n”; print “We found $EcoRI in your sequence\n"; } else { print “We did not found $EcoRI in your sequence\n”; }

  11. Perl Literals • Literals are constant values that you embed directly in the program code. String and numeric literals. • String literals are enclosed by single quotes (') or double quotes ("): • The difference: variables and certain special escape codes are interpolated into double quoted strings, but not in single-quoted ones.

  12. Special Escape Code

  13. Perl String Literals #!/usr/bin/perl # file: enzyme.pl $EcoRI = ‘GAATTC’; $Seq=<STDIN>; If ($Seq=~$EcoRI)‏ { print “Your seq=$Seq\n”; print “We found $EcoRI in\tyour sequence\n"; } else { print “We did not found $EcoRI in your sequence\n”; }

  14. Perl Backtick Strings • You can also enclose a string in backtics (`). This has the unusual property of executing whatever is inside the string as a Linux system command, and returning its output: #! /usr/local/bin/perl # file: backtics.pl $command=`pwd`; print “$command\n”; $command=`ls`; print “$command\n”;

  15. Perl Numeric Literals • You can refer to numeric values using integers, floating point numbers, scientific notation, and so on. #!/usr/bin/perl # file: literal.pl $x=123; # an integer $x=1.23; # a floating point number $x=-1.23; # a negative floating point number $x=1_000_000; # you can use _ to improve readability $x=1.23E45; # scientific notation print “The number is $x \n”;

  16. List • The last type of literal that Perl recognizes is the list, which is multiple values strung together using the comma operator (,) and enclosed by parentheses. ('one', 'two', 'three', 1, 2, 3, 4.2);

  17. Perl Operators Numeric and String Operators • Perl has numerous operators that perform operations on string and numeric values.

  18. Logic Operators • These operators compare strings or numbers, returning TRUE or FALSE:

  19. File Operators • Perl has special file operators that can be used to query the file system. These operators generally return TRUE or FALSE.

  20. Try to practice the Perl programs we used in the lecture in computer. Assignments

More Related