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.

Slides:



Advertisements
Similar presentations
Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
Advertisements

PL/SQL.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
CS 898N – Advanced World Wide Web Technologies Lecture 8: PERL Chin-Chih Chang
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
CSC 4630 Meeting 9 February 14, 2007 Valentine’s Day; Snow Day.
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Lecture 2 BNFO 135 Usman Roshan. Perl variables Scalar –Number –String Examples –$myname = “Roshan”; –$year = 2006;
Introduction to Perl Part III By: Cedric Notredame Adapted from (BT McInnes)
Iteration and Simple Menus Deterministic / Non-deterministic loops and simple menus.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
PL/SQL Loops. Building Logical Conditions All logical conditions must yield a boolean condition. You can build a simple Boolean condition by combining.
Control Structures. Important Semantic Difference In all of these loops we are going to discuss, the braces are ALWAYS REQUIRED. Even if your loop/block.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Meet Perl, Part 2 Flow of Control and I/O. Perl Statements Lots of different ways to write similar statements –Can make your code look more like natural.
Control Structures. if-elsif-else semantically the same as C/C++ syntactically, slightly different. if ($a > 0){ print “\$a is positive\n”; } elsif ($a.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Books. Perl Perl (Practical Extraction and Report Language) by Larry Wall Perl 1.0 was released to usenet's alt.comp.sources in 1987 Perl 5 was released.
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
13 More Advanced Awk Mauro Jaskelioff (originally by Gail Hopkins)
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Revision Lecture Mauro Jaskelioff. AWK Program Structure AWK programs consists of patterns and procedures Pattern_1 { Procedure_1} Pattern_2 { Procedure_2}
Introduction to Unix – CS 21
BY A Mikati & M Shaito Awk Utility n Introduction n Some basics n Some samples n Patterns & Actions Regular Expressions n Boolean n start /end n.
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
5 1 Data Files CGI/Perl Programming By Diane Zak.
LIN Unix Lecture 7 Hana Filip. LIN Text Processing Command Line Utility Programs (cont.) sed LAST WEEK wc sort tr uniq awk TODAY join paste.
Iteration While / until/ for loop. While/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initialise condition.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
CPTG286K Programming - Perl Chapter 4: Control Structures.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
CSCI 330 UNIX and Network Programming Unit IX: Shell Scripts.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
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.
INLS 560 – S TRINGS Instructor: Jason Carter. T YPES int list string.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
CSC 4630 Meeting 17 March 21, Exam/Quiz Schedule Due to ice, travel, research and other commitments that we all have: –Quiz 2, scheduled for Monday.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
Perl: Practical Extraction & Reporting Language RL Schwartz, Learning Perl, RL Schwartz & L Wall, Programming Perl, O’Reilly & Associates.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 this week – last section on Friday. Assignment 4 is posted. Data mining: –Designing functions.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
String and Lists Dr. José M. Reyes Álamo.
CSC 4630 Meeting 7 February 7, 2007.
Control Flow Constructs: Conditional Logic
Perl Programming Language Design and Implementation (4th Edition)
Chapter 5 - Control Structures: Part 2
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
ITM 352 Flow-Control: Loops
Perl Variables: Array Web Programming.
Control Structures: for & while Loops
PERL: part II hashes, foreach control statements, and the split function By: Kevin Walton.
String and Lists Dr. José M. Reyes Álamo.
Topics Basic String Operations String Slicing
Topics Basic String Operations String Slicing
Topics Basic String Operations String Slicing
Presentation transcript:

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 of white-space delimited strings (ignoring case) with frequency counts ordered first by frequency and then lexicographically by ASCII character order. Format is

Problem (2) What do we need to solve it in Perl? Read a line from a = <>; Read the whole file, line by line, and do something to each line while (<>) {something} Note that each line shows up in the variable $_ so that you don’t have to do an assignment statement if you don’t want to.

Problem (3) Try 1: Make a one line input file: The quick brown fox Make a Perl program that reads and writes it: while (<>) {

Problem (4) Try 2: Same program, put two lines in the input file. Try 3: Change the upper case to lower case. Perl knows about tr and assumes it works on $_ Syntax is tr/ab/cd/

Problem (5) Try 4: Now we need to separate the array containing the current line into individual words. Perl can help with split which takes $_ by default, splits it on whitespace by default, and puts the result where you = split; Redo your program to handle this and print one word per line.

Problem (6) Try 5: Collect the lines in an array and print the array, one word per line. Perl knows the array iteration similar to Awk: foreach { }. If you don’t specify a loop variable, Perl uses $_

Problem (7) Try 6: We need the words in alphabetical order. Perl knows sort as a function on an = does the job. Fix your program so that it prints the words in lexicographic order, one per line.

Problem (8) Try 7: Where is the UNIX uniq command when we need it?

Control Structures Sequence: Statements separated or terminated by ; (semicolon) If-Then-Else: if (c) {s1} else {s2} Note that c as a conditional expression is false if its value is the string () or the single character 0 (zero). Otherwise c is true

Control Structures (2) Fancier If-Then-Else unless (c) {s} is equivalent to if (c) { } else {s} if (c1) {s1} elsif (c2) {s2} elsif (c3) {s3} … else {sn}

Control Structures (3) While-Do: while (c) {s} until (c) {s} is equivalent to while (!c) {s} do {s} while c is equivalent to s; while (c) {s}

Control Structures (4) We have the fourth version also do {s} unless c is equivalent to s; unless (c) {s}

Control Structures (5) Loops with “counters” for (e; c; i) {s} is equivalent to e; while (c) {s; i} Counter issues: –Loop variable local to loop? –Value of loop variable after loop exit?

Control Structures (6) foreach $i {s} The variable $i ranges over the values of the array and can be referenced by s foreach {s} Uses the default index variable $_ Check the behavior = (1,3,5,7); foreach $i {$i *=3}