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.

Slides:



Advertisements
Similar presentations
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
Advertisements

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.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Regular Expressions Regular Expression (or pattern) in Perl – is a template that either matches or doesn’t match a given string. if( $str =~ /hello/){
More Regular Expressions. List/Scalar Context for m// Last week, we said that m// returns ‘true’ or ‘false’ in scalar context. (really, 1 or 0). In list.
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.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
INTRODUCTION TO C PROGRAMMING LANGUAGE Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
THE BIG PICTURE. How does JavaScript interact with the browser?
Sys.Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 18: Regular Expressions in PHP.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Creating your first C++ program
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Linux Operations and Administration
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.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
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
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Introduction to Unix – CS 21
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
5 1 Data Files CGI/Perl Programming By Diane Zak.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Artificial Intelligence Lecture No. 26 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
CMSC 1041 Introduction to C Creating your first C program.
A Few More Functions. One more quoting operator qw// Takes a space separated sequence of words, and returns a list of single-quoted words. –no interpolation.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
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.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
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,
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
Learning Javascript From Mr Saem
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
Perl Backticks Hashes printf Variables Pragmas. Backticks.
PHP using MySQL Database for Web Development (part II)
Introduction to C Topics Compilation Using the gcc Compiler
Discussion 4 eecs 183 Hannah Westra.
Information and Computer Sciences University of Hawaii, Manoa
Running external programs
Lecture 9 Shell Programming – Command substitution
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
Scripts & Functions Scripts and functions are contained in .m-files
More Selections BIS1523 – Lecture 9.
Programming in Perl Introduction
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
CSC 352– Unix Programming, Fall 2012
The Python interpreter
The Python interpreter
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

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

Evaluate Perl code $code = “print (‘Hello World\n’)”; eval $code; #prints Hello World trap errors –using block notation, if there are any run-time errors, eval returns undef and sets error in either block notation {…} or expression notation “…” is allowed –block syntax checked at compile time, so faster. Expression checked at run-time. –If no errors, executes code as though you had actually typed the code in your Perl script. both forms set errors in eval

Back-ticks Third kind of quoted string Executes an external program and returns the = `ls *.html`; Your script will run “ ls *.html ” from the command prompt, and store the output of that program Back-ticks do interpolation just like double quotes Note that this is not the same as the system function –system returns return value of the called program, not the output

Quoting operators You may get strings that end up looking messy because of all the quotes: $s = “He said \“She said \“They said \“This is bad.\”\”\””; can use the quoting operator qq// to ‘choose your own quotes’. –Much like choosing your own delimiters in pattern matching $s = “He said qq/She said qq(They said qq[This is bad])/” –You could argue this doesn’t look much better You could be right.

Many quoting operators In each case below, you can use any non-alpha-numeric character for the delimiter, just as you can with m// and s/// q// - single quoted string qq// - double quoted string –does interpolation qx// – back-ticked string qw// - quote words –qw/Mon Tue Wed/  (“Mon”, “Tue”, “Wed”) qr// - quote regular expression –evaluate string as though it’s a RegExp –Then use result in an actual pattern match –mostly for efficiency – don’t worry about this one too much

map map expression list –evaluate expression (or a block) for each value of list. Sets $_ to each value of list, much like a foreach loop –Returns a list of all results of the = map {split ‘ ’ –Set $_ to first member run split ‘ ’ (split acts on $_ if no arg provided), push results set $_ to next member = qw/morning afternoon evening = map  (“Good morning”, “Good afternoon”, Good evening”, “Good night”)

grep Similar to map (but not exact) returns a list of all members of the original list for which evaluation was true. –(map returns list of all return values of each evaluation) Typically used to pick out lines you want to = grep –removes all lines beginning with comments –Assigns $_ to each member then evaluates the pattern match. If pattern match is true, the $_ is added

do yeah, yeah, this should have been included with the looping constructs. My bad. Similar to C/C++ do/while construct. Execute entire block following do once. If block followed by a while modifier, check the conditional, and then redo the loop. Major Difference: in Perl, do is not a looping structure. Therefore, cannot use next, last, or redo.