2ex.1 Lists and Arrays. 2ex.2 Comments on exercises Always run your script with “ perl -w ” and take care of all warnings  submitted scripts should not.

Slides:



Advertisements
Similar presentations
Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
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.
Perl Arrays and Lists Software Tools. Slide 2 Lists l A list is an ordered collection of scalar data. l A list begins and ends with parentheses, with.
COMP234 Perl Printing Special Quotes File Handling.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
Perl Arrays and Lists Learning Objectives: 1. To understand the format and the declaration of Arrays & Lists in Perl 2. To distinguish the difference between.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
1ex.1 Perl Programming for Biology Exercise 1 The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel March 2009 Eyal Privman.
Perl File I/O and Arrays. File I/O Perl allows to open a file to read, write, or append As well as pipe input or output to another program. —We get to.
Guide To UNIX Using Linux Third Edition
3.1 Ifs and Loops. 3.2 Revision: variables Scalar variables can store scalar values: Variable declaration my ($priority); Numerical assignment $priority.
2.1 Lists and Arrays Summary of 1 st lesson Single quoted and double quoted strings Backslash ( \ ) – the escape character: \t \n Operators:
3ex.1 Note: use strict on the first line Because of a bug in the Perl Express debugger you have to put “use strict;” on the first line of your scripts.
PHP : Hypertext Preprocessor
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Noadswood Science,  To understand what strings are and how decisions are made Thursday, September 17, 2015.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
CPTG286K Programming - Perl Chapter 3: Arrays and List Data.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Chapter 02 (Part III) Introduction to C++ Programming.
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
COMP519: Web Programming Autumn 2010 Perl Tutorial: The very beginning  A basic Perl Program The first line Comments and statements Simple printing 
Introduction to Programming with RAPTOR
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
3.1 Revision: variables & arrays Array declaration Array = ('A','B','C','D'); = = (); Array.
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
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
ENG College of Engineering Engineering Education Innovation Center 1 More Script Files in MATLAB Script File I/O : Chapter 4 1.Global Variables.
Computer Programming for Biologists Class 6 Nov 21 th, 2014 Karsten Hokamp
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
2.1 Lesson 2: Scalar Functions and Arrays “Perl programming is an empirical science!” - Larry Wall.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
Arrays and Lists. What is an Array? Arrays are linear data structures whose elements are referenced with subscripts. Just about all programming languages.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Getting Started With Python Brendan Routledge
Pamela Moore & Zenia Bahorski
Chapter 2 Assignment and Interactive Input
Variables, Expressions, and IO
Basic operations in Matlab
Intro to PHP & Variables
Perl Variables: Array Web Programming.
Teaching London Computing
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
T. Jumana Abu Shmais – AOU - Riyadh
Introduction to TouchDevelop
Our Environment We will exercise on Microsoft Visual C++ v.6
Input and Output Python3 Beginner #3.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
Presentation transcript:

2ex.1 Lists and Arrays

2ex.2 Comments on exercises Always run your script with “ perl -w ” and take care of all warnings  submitted scripts should not produce any warnings When you us problems you run into, send the script, and copy the running of it (with “ perl -w ”) and the output from the command prompt window When submitting exercises by write your name and the exercise number in the subject line (e.g. “ Israel Israeli perl ex. 2 ”) Write a separate file for each question, and name the scripts: “ ex2.1.pl ”, “ ex2.2.pl ”, “ ex2.3.pl ”… Use meaningful name for variables.

2ex.3 Adding comments Comments: The # symbol, and anything from it to the end of the line is ignored. # get start and stop values from the user my $start = my $stop = # calculate string length my $length = $start - $stop + 1;

2ex.4 Adding comments Comments: If you want to insert a comment of multiple lines, you can use =begin and =cut. =begin This program prints stuff. Here you can write any text you want and you don’t need any # =cut print "stuff\n";

2ex.5 Undefined variables my $a; print($a+3); Use of uninitialized value in addition (+) 3 print("a is :$a:"); Use of uninitialized value in concatenation (.) or string a is ::

2ex.6 Lists and arrays A list is an ordered set of scalar values: (1,2,3,"fred") An array is a variable that holds a list: = (1,2,3,"fred"); You can access an individual array element: print $a[1];2 $a[0] = "*"; 3210 scalar 4scalar 3scalar 2scalar "fred"321

2ex.7 Lists and arrays You can easily get a sub-array: = (1,2,3,"fred","bob"); print $a[1];2 You can extend an array as much as you like: = (1,2,3) $b[5] = is now (1,2,3,undef,undef,6) "bob""fred"321

2ex.8 Lists and arrays Assigning to arrays: = (3..6); (3,4,5,6) = qw(a b cat d); ("a","b","cat","d") my = (1..5); $a=1; Counting array elements: print 4

2ex.9 Reading and printing arrays You can read lines from the standard input in list context: = will store all the lines entered until the user hits ctrl-z. You can interpolate arrays and array elements into strings: abcatd print a b cat d print "$b[2] is the third element of cat is the third element

2ex.10 Manipulating arrays – push & pop = (1,2,3,4,5); = (1,2,3,4,5); my $x = print $x;5

2ex.11 shift & unshift = (1,2,3); = (1,2,3); my $x = print $x;1

2ex.12 split & join my = split(" ", "You talkin to me? You talkin to = = split("", "You talkin to me? You talkin to = ("Y","o","u"," ","t","a","l","k","i","n"," ",...) my $str = print "$str\n"; "You-talkin-to-me?-You-talkin-to-me?"

2ex.13 Reversing lists = ("yossi","bracha","moshe"); print join(";", moshe;bracha;yossi (You can also reverse strings…)

2ex.14 Sorting lists Default sorting is alphabetical: = sort("yossi","bracha","moshe"); is ("bracha","moshe","yossi") = sort(1,3,9,81,243); is (1,243,81,9) Other forms of sorting require subroutine definition: = sort(compare_sub 1,3,9,81,243); We’ll get to that latter…

2ex.15 Class exercise 2 Write the following scripts: 1.Read a number from the first line of input, and then read the rest of the lines and print the one selected by that number 2.Read a list of numbers separated by spaces, and print those numbers in reverse order, separated by slashes (/) 3.Read a list of words separated by spaces, sort and print them 4*.Like in 2, but double the first and the last numbers 5*.Like in 3, but reverse the order of the letters of the last word

2ex.16 Perl Express

2ex.17 The Perl-Express editor

2ex.18 Output tab Output of run Perl Express – running a script Run the script Warnings and errors

2ex.19 Perl Express – entering input Click “ Std. Input ”

2ex.20 Click “ i/o ” Perl Express – entering input

2ex.21 Go back to “ Std. Output ” Perl Express – entering input Enter input Note: Perl Express can’t be given input with a ctrl-Z, so you can’t run a script =

2ex.22 Class exercise 2 (cont.) Run the script from question 2 in Perl Express

2ex.23 The Debugger

2ex.24 Debugging A complex program will never work correctly the first time you run it! So: Write the program one stage at a time and check that it works Use a debugger to execute the program step by step Next line that will be executed

2ex.25 Next line that will be executed Start debuggerStep one line Run continuously Add breakpoint – to run until this point

2ex.26 You can “ watch ” your variables as they change their values using the “ Watch List ” window Mark a variable name 1 Click “ Add Watch ” 2 The variable will be displayed 3

2ex.27 Enter an expression that will be evaluated In order to “ watch ” arrays and more complex data use the “ Evaluate ” button

2ex.28 Class exercise 2 (cont.) Follow the working of the script from question 2 in the debugger. Watch the value of each variable.