More Variables and Data Types: references/matricies

Slides:



Advertisements
Similar presentations
R for Macroecology Aarhus University, Spring 2011.
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Basic Elements of C++ Chapter 2.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
 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.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
CST8177 bash Scripting Chapters 13 and 14 in Quigley's "UNIX Shells by Example"
Linux+ Guide to Linux Certification, Third Edition
Linux Operations and Administration
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
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.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Yupu Liang cbio at MSKCC
Perl Language Yize Chen CS354. History Perl was designed by Larry Wall in 1987 as a text processing language Perl has revised several times and becomes.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Comments in PHP In PHP, we use // to make a singleline comment or /* and */ to make a large comment block. Comment is a part of your PHP code that will.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Looping and Counting Lecture 3 Hartmut Kaiser
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia Homework 4 not yet graded …
Random Bits of Perl None of this stuff is worthy of it’s own lecture, but it’s all a bunch of things you should learn to use Perl well.
More Perl Data Types Scalar: it may be a number, a character string, or a reference to another data type. -the sigil $ is used to denote a scalar(or reference)
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation Creating procedures by capturing common patterns.
Week Four Agenda Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
The Scripting Programming Language
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
Linux Administration Working with the BASH Shell.
A FIRST BOOK OF C++ CHAPTER 7 ARRAYS. OBJECTIVES In this chapter, you will learn about: One-Dimensional Arrays Array Initialization Arrays as Arguments.
Regular Expressions In Javascript cosc What Do They Do? Does pattern matching on text We use the term “string” to indicate the text that the regular.
CS 350 Lecture 3 UNIX/Linux Shells by İlker Korkmaz and Kaya Oğuz.
Chapter 2 Writing Simple Programs
Chapter Topics The Basics of a C++ Program Data Types
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
Introduction to Perl: Part II
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
1-1 Logic and Syntax A computer program is a solution to a problem.
System Administration Introduction to Scripting, Perl Session 5 – Fri 23 Nov 2007 References: Perl man pages Albert Lingelbach, Jr.
Chapter 2 Scanning – Part 1 June 10, 2018 Prof. Abdelaziz Khamis.
Perl Programming Language Design and Implementation (4th Edition)
Running external programs
Basic Elements of C++.
Topic: Functions – Part 2
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
Scripts & Functions Scripts and functions are contained in .m-files
Intro to PHP & Variables
Basic Elements of C++ Chapter 2.
Arrays, For loop While loop Do while loop
Introduction to Python
Introduction to Python
Subroutines Web Programming.
Use of Mathematics using Technology (Maltlab)
Matlab tutorial course
CSE 303 Concepts and Tools for Software Development
Intro to PHP.
awk- An Advanced Filter
Introduction to Bash Programming, part 3
PHP –Regular Expressions
Presentation transcript:

More Variables and Data Types: references/matricies References: can used to save memory usage or create complex data structures. my @num_arr = (1,3,5); #an array my $array_ref = \@num_arr; #a reference to @num_arr my $new_arr_ref = []; #initialize an empty array ref Deferencing variables is done with a leading ‘$’. ie: ${$scalar} or ${@arr} or ${%hash} Matricies: N-dimensional arrays (Matricies) can be constructed from lists of arrays using references. This table: Is represented by this structure: my @arr_1 = (‘A’,1,’Two’); #first row my @arr_2 = (‘X’,’V’,9); #second row my @arr_3 =(.04,’T’,’you’); #third row my @matrix = (\@arr_1,\@arr_2,\@arr_3); #build the matrix print “Row 1 Col 1:” . $matrix[0][0] . “| Row 1 Col 2:” . $matrix[0][1] . “\n”; A 1 Two X V 9 .04 T you

System Calls: system() and exec() Any command you can execute on the command line, can be executed from within Perl The two functions to accomplish this are system() and exec() perldoc -f system [or exec] for more info. Both take as an argument a string which represents a valid command, or a command in the form of an array (where the command, and all its arguments are held in consecutive elements of the array). It is most common to use command strings. system(): will wait while the command is executing and you can capture any output from the command as well as evaluate the exit code. Once the command has finished running, the calling perl script will continue to run. exec(): will run the command and exit the perl script at this point. This is generally not desired- use system() If in doubt.

Regular Expressions if ($string =~ /world/) { print “passes\n”; From wikipedia: “A regular expression (abbreviated as regexp or regex, with plural forms regexps, regexes, or regexen) is a stringthat describes or matches a set of strings, according to certain syntax rules.” Perl is considered to have the most full featured, and more importantly, consistant regex syntax. Most current languages which provide regex support try to make their implementations Perl compatible. Example: my $string = “hello world”; #the special operator =~ is used for regular expressions #our variable is being tested (using the =~) for the pattern described between the // #in this case, we are testing if the substring ‘world’ is contained in our string #if there is a match, this operation will return true, if not it returns false if ($string =~ /world/) { print “passes\n”; } else { print “fails\n”; }

Regular Expressions cont. Regular expressions are a vast topic. It is easy to get started, and just as easy to get frustrated when building complex regular expressions. Be patient, and play around with them to get a feel for how they work. Some Excellent Resources Are: Learning Perl Regex Chapter (handout) Regex Summary: (handout) and http://www.cs.tut.fi/~jkorpela/perl/regexp.html Wikipedia General Overview: http://en.wikipedia.org/wiki/Regular_expression Wikipedia Perl examples: http://en.wikipedia.org/wiki/Perl_regular_expression_examples Good Intro Guide: http://www.troubleshooters.com/codecorn/littperl/perlreg.htm From above guide : Regular expressions is a HUGE area of knowledge, bordering on an art. Rather than regurgitate the contents of the PERL documentation or the plethora of PERL books at your local bookstore, this page will attempt to give you the 10% of regular expressions you'll use 90% of the time.

Exercises