Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.

Slides:



Advertisements
Similar presentations
Searching using regular expressions. A regular expression is also a ‘special text string’ for describing a search pattern. Regular expressions define.
Advertisements

The Linux Operating System Lecture 6: Perl for the Systems Administrator Tonga Institute of Higher Education.
Dynamic Arrays Lecture 4. Arrays In many languages the size of the array is fixed however in perl an array is considered to be dynamic: its size can be.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Programming and Perl for Bioinformatics Part III.
ISBN Regular expressions Mastering Regular Expressions by Jeffrey E. F. Friedl –(on reserve.
CS 898N – Advanced World Wide Web Technologies Lecture 8: PERL Chin-Chih Chang
1 HTML Markup language – coded text is converted into formatted text by a web browser. Big chart on pg. 16—39. Tags usually come in pairs like – data Some.
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.
PERL Part 3 1.Subroutines 2.Pattern matching and regular expressions.
Practical Extraction & Report Language Picture taken from
CS 330 Programming Languages 09 / 30 / 2008 Instructor: Michael Eckmann.
Scripting Languages Chapter 8 More About Regular Expressions.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Prof. Alfred J Bird, Ph.D., NBCT Office – Wheatly 2nd floor Office Hours – MW 3:00PM to 4:00PM.
Binary Search Trees continued Trees Draw the BST Insert the elements in this order 50, 70, 30, 37, 43, 81, 12, 72, 99 2.
Prof. Alfred J Bird, Ph.D., NBCT Office – Wheatly 2nd floor Office Hours – MW 3:00PM.
Lecture 7: Perl pattern handling features. Pattern Matching Recall =~ is the pattern matching operator A first simple match example print “An methionine.
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormack 3rd floor 607.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students – * Office – Wheatly.
Prof. Alfred J Bird, Ph.D., NBCT Door Code: * Office – McCormick 3rd floor 607 Office.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Prof. Alfred J Bird, Ph.D., NBCT -bird.wikispaces.umb.edu/ Office – McCormick 3rd floor.
Regular Expressions.
CS 330 Programming Languages 10 / 07 / 2008 Instructor: Michael Eckmann.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
CS346 Regular Expressions1 Pattern Matching Regular Expression.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Regular Expressions CS 2204 Class meeting 6 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students.
Regular Expressions Pattern and String Matching in Text.
Karthik Sangaiah.  Developed by Larry Wall ◦ “There’s more than one way to do it” ◦ “Easy things should be easy and hard things should be possible” 
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Unit 11 –Reglar Expressions Instructor: Brent Presley.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
1 Lecture 10 Introduction to AWK COP 3344 Introduction to UNIX.
Part 4 Arrays: Stacks foreach command Regular expressions: String structure analysis and substrings extractions and substitutions Command line arguments:
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3nd floor, room 607 Office Hours –Tuesday.
CS 330 Programming Languages 09 / 30 / 2008 Instructor: Michael Eckmann.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Regular Expressions.
CS 330 Class 7 Comments on Exam Programming plan for today:
IT441 Network Services Administration
IT441 Network Services Administration
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
Introduction to Scripting
Perl Variables: Array Web Programming.
CSCI 431 Programming Languages Fall 2003
Creating your first C program
Regular Expressions
String Processing 1 MIS 3406 Department of MIS Fox School of Business
Presentation transcript:

Prof. Alfred J Bird, Ph.D., NBCT Door Code for IT441 Students – * Office – Wheatly 2nd floor Office Hours – MW 3:00PM to 4:00PM

 Perl normally treats lines beginning with a # as a comment.  Get in the habit of including comments with your code.  Put a comment block at the beginning of your code which includes your name, the name of the module, date written and the purpose of the code.

#!/usr/bin/perl -w # #Module Name: helloWorld.pl # #Written by Alfred J Bird, Ph.D., NBCT #Date Written – 21 September 2011 #Purpose: To print out the string “Hello world!” # #Date Modified – 25 September, 2011 #Purpose of modification: To fix spelling errors. #Modified by: Al Bird # print “Hello world! \n”;

 To find out how many elements are in an array:  my $lastIndex = $#array  push() and pop()  Adds and removes elements from the high end of the array  shift() and unshift()  Adds and removes elements from the low end of the array

 Write a program to create an array with the names of the first six months in it and then print them out.  Modify the program using push to add the next six months one at a time to the array.  Print out the array each time including the index of the last element.  Experiment with the pop, shift and unshift functions.

 Given a text file (i.e. gettysburg.txt in my home directory) write a program to find if the a given word is used in the file.  Use the split function as such:  my $word (split)  This will break up the line into words separated by whitespace characters  If the word is found, print out a message indicating such.

 Given a text file (i.e. gettysburg.txt in my home directory) write a program to find if the a given word is used in the file.  Use the split function as such:  my $word (split)  This will break up the line into words separated by whitespace characters  If the word is found, print out a message indicating such.  Go to readAndPrint1.pl in my directory for a solution.

 Often called regex  One of the most useful features of Perl  Available in most programming languages  You used it in BASH  What does this do?  s/abc/ABC/  Welcome to the world of regular expresions

 Given a text file (i.e. gettysburg.txt in my home directory) write a program to find if the a given word is used in the file.  Use a regular expression such as  /and/  If the word is found, print out a message indicating such.

 Given a text file (i.e. gettysburg.txt in my home directory) write a program to find if the a given word is used in the file.  Use a regular expression such as  /and/  If the word is found, print out a message indicating such.  Go to readAndPrint.pl in my directory for a solution.

 What is different between the two methods of searching?  What if I want to ignore the case of the letters?  How would you modify the readAndPrint1.pl program to check without regard to capitalization?  It is not very easy is it!  With regular expressions it is much simpler.  /$word/i

 What if I wanted to find a pattern only at the start of a line or at the end of a line?  In a Regex we can use anchors.  To indicate the pattern must be at the start of a line we use the ^  i.e. /^The/  To indicate the pattern must be at the end of the line we use the anchor $  i.e./end$/

 We can make our Regex more general by using metacharacters.  See the table on page 167 in the text  Four of the more common metacharacters are: .Matches any character except newline  ? Preceding character or group may be present 0 or 1 time  +Preceding character or group is present 1 or more times  *Preceding character or group may be present 0 or more times

 Write a program that:  Reads the file alice.txt in my home directory  Checks to see if any given word is present without regard to capitalization  Modify the program to see if there are any numbers in the file

 Modify the earlier program to accept a file name as input and check for a word entered from the keyboard in the file.

 Read pages 153 to 177 in the textbook.