Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Scalar Variables Start the file with: #! /usr/bin/perl –w No spaces or newlines before the the #! “#!” is sometimes called a “shebang”. It is a signal.
Introduction to Perl Learning Objectives: 1. To introduce the features provided by Perl 2. To learn the basic Syntax & simple Input/Output control in Perl.
Introduction to Perl. How to run perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Your program/script.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
An Introduction to Unix Shell Scripting
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Week 1 Algorithmization and Programming Languages.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to Perl Yupu Liang cbio at MSKCC
Introduction to PHP Advanced Database System Lab no.1.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to Unix – CS 21
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
1 Introduction to Perl CIS*2450 Advanced Programming Techniques.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
5 1 Data Files CGI/Perl Programming By Diane Zak.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Scripting Languages Course 3 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Introduction to Objective Caml. General comments ML is a purely functional language--there are (almost) no side effects There are two basic dialects of.
Perl Lab #11 Intro to Perl Debbie Bartlett. Perl Lab #1 2 Perl Practical Extraction and Report Language –or- Pathologically Eclectic Rubbish Lister Created.
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
Bioinformatics Introduction to Perl. Introduction What is Perl Basic concepts in Perl syntax: – variables, strings, – Use of strict (explicit variables)
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
Perl Subroutines User Input Perl on linux Forks and Pipes.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
Scripting Languages Course 7 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Last week: We talked about: History of C Compiler for C programming
Chapter 2 Introduction to C++ Programming
Shell Scripting March 1st, 2004 Class Meeting 7.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Variables, Expressions, and IO
Getting Started with C.
Intro to PHP & Variables
Perl for Bioinformatics
Computer Science and an introduction to Pascal
Introduction to C++ Programming
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C Topics Compilation Using the gcc Compiler
12th Computer Science – Unit 5
Running a Java Program using Blue Jay.
Introduction to Perl Learning Objectives:
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …

Perl? perl? PERL? The name of the language is "Perl". Any expansion you may read was made up after the fact. "PERL" is *never* correct. The executable program that interprets Perl code is "perl" "Only perl can parse Perl" See also: perldoc –q difference

Basic Structure Bares resemblances (but not much) to C or Java semi-colons separate executable statements { } delimit blocks, loops, subroutines Comments begin with # and extend to end of line No main() function – code executed top-down. Function arguments are comma-separated parentheses are (usually) optional

What is Perl? Perl is a FREE, open source programming language created by Larry Wall General philosophy: practical and quick Non philosophy: structured or elegant Know for Text processing of strings and files Uses regular expressions heavily Attractive for writing short and quick solutions to many text processing tasks

Running a Perl Program A Perl program is just a text file (ie pure ASCII) We write these files using text editors such as notepad, notepad++ etc. The extension for a Perl program is.pl so a file such as myprog.pl should be written to contain a Perl program. Within DOS ( or Unix command line ) we can execute myprog.pl using the following command C:\perl myprog.pl perl is the Perl interpreter that runs myprog.pl

A very simple program using Print # Type and run this print "Hello", " ", "World", "\n"; print ("Five plus three: ", 5+3); # This is a comment. # The following command reads what you # type and does nothing with the input # WHY? Run it with and without the command! $dummy= NEXT:store the above as simple1.pl

Easy way to run the programs Open two windows in XP The first is for the editor The second is the directory window. Leaving these two windows open simplifies the programming considerably Step 1: Write the program in Notepad Save the program as say myprog.pl Click on the directory window that contains myprog.pl and then double click on myprog.pl This will execute the program automatically since.pl files are associated with the interpreter perl.

Example Development and Execute Double Click

Command Line execution type to exec

Another Simple Perl program #!/usr/bin/perl –w # only for Unix programs #This is your first Perl program # It prints data to the screen and reads information from the keyboard print "Hello mister user\n"; # Print introduction print 'What is your name:'; $line = ; # Grabs everything up to and including the \n chomp($line);# removes the \n print 'Well ',$line, " welcome to Perl \n\n\n"; print 'HIT return to exit!'; $dummy= #The above line keeps the window open so you can look at the output

First Complete Program print "Hello World\n"; A few ways to execute this code: "interactive mode" start the perl interpreter type the code send end-of-file (CTRL-D in Unix) Put code in a file, give perl interpreter the filename perl hello.pl Tell the OS what program should execute the contained code shebang + chmod...

Before we develop more complicated progs… Perl is a very lenient language. It will allow you to do a whole host of things that you probably shouldn't be able to. printing a variable that you never assigned to trying to add 5 + 'foo' If you want Perl to warn you about this sort of thing (and you often do) add the following command to the start of your program use warnings;

Variables Three major types of Perl variables Scalars – single values Arrays – contain lists of values Hashes – "associative arrays" There are others (filehandles, typeglobs, subroutines)… We will cover some of these later

Scalars A Scalar variable contains a single value. Scalar variable types include int ( examples, 21, 231, -4221) Float( examples , ) Strings(examples “Richard”, ‘Reality what a concept!’) Scalar variable name starts with a $ Next character is a letter or underscore Remaining characters: letters, numbers, or underscores.

Example variable initializations $num = 42; $letter = 'a'; $name = 'Paul'; NOTE! Strings are *single values*! $grade = 99.44; $Big_String = 'The Quick Brown Fox…';

Program using integer variables

Strings String constants are enclosed within Double quotes( “Hello there”, “You’ve got to be kidding\n”) Single quotes( ‘Now is the time”, ‘for all good men’) The double quotes are used when you want control directives, \n,\t etc, to be processed. \n represents a new line. ie carriage return! \t is a tab operation. There are others Question: How do you print the following Now you’ve done it.

Perl When Perl sees an expression that doesn’t make sense, such as a variable that has not been given a value, it tends to just silently pass over the problem and use some default value such as undef. Perl may make the wrong assumption! So make sure it does what you want it to! Perl is known to compile all kinds of gobbly gook.

Error Comments If the program you type in has a syntax error then a comment will be printed and the program will exit. If you are using notepad++ and click on the.pl file to execute it you will have a problem if there is an error. The output will flash and disappear. Example: Take the previous program and remove the first ; Then resave it and double click on the.pl file. WHAT DO YOU SEE??? Well, What can we do to see its comments.

Program that needs input #Type this in and run it using the dos command line # Make several errors and see what happens. print “Enter the value of x: “; $x= ;# Reads line up to and including the \n chomp($x);# Removes the \n print “Enter the value of y: “; $y= ; chomp($y); $z=$x+$y; # Note the double quotes in the following command! print “The sum of $x and $y is “, $z,”\n”; print ‘HIT return to exit!’; $dummy= ;

Example Error(Missing ;) NOTE: command line execution