Perl Challenge Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: 818-677-4954 “UNIX for Programmers and Users” Third Edition, Prentice-Hall,

Slides:



Advertisements
Similar presentations
The Linux Operating System Lecture 6: Perl for the Systems Administrator Tonga Institute of Higher Education.
Advertisements

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.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
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.
Perl Functions Software Tools. Slide 2 Defining a Function l A user-defined function or subroutine is defined in Perl as follows: sub subname{ statement1;
Lecture 2 BNFO 240. Perl online references
Perl Functions Learning Objectives: 1. To learn how to create functions in a Perl’s program & how to call them 2. To learn how to pass [structured] arguments.
7ex.1 Hashes. 7ex.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Eyal Enter a phone number:
Regular Expressions Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition,
8.1 Hashes (associative arrays). 8.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Dudi Enter a phone.
Lecture 2 BNFO 135 Usman Roshan. Perl variables Scalar –Number –String Examples –$myname = “Roshan”; –$year = 2006;
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
Awk challanges Prof. Andrzej (AJ) Bieszczad Phone: awk Challenges Find out what the following awk scripts do: END.
Stream-Oriented, Non-Interactive EDitor sed Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and.
9.1 Hashes. 9.2 Let's say we want to create a phone book... Enter a name that will be added to the phone book: Ofir Enter a phone number: Enter.
2.1 Lists and Arrays Summary of 1 st lesson Single quoted and double quoted strings Backslash ( \ ) – the escape character: \t \n Operators:
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.
Perl Functions Learning Objectives: 1. To learn how to create functions in a Perl’s program & how to call them 2. To learn how to pass [structured] arguments.
Computing Theory: BBC Basic Coding Year 11. Lesson Objective You will: Be able to define what BBC basic is Be able to annotate BBC basic code Be able.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Lecture 8: Basic concepts of subroutines. Functions In perl functions take the following format: – sub subname – { my $var1 = $_[0]; statements Return.
Subroutines Just like C, PERL offers the ability to use subroutines for all the same reasons – Code that you will use over and over again – Breaking large.
11.1 Subroutines A function is a portion of code that performs a specific task. Functions Functions we've met: $newStr = substr
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Programmable Text Processing with awk Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users”
Perl (Tutorial II) NLP Course 07 Examples. EXAMPLE 1 #!/usr/bin/perl #Opens and reads the file "sentences" (input file) line by line. #For the i-th sentence.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Bioinformatics 生物信息学理论和实践 唐继军
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Chapter 9: Perl (continue) Advanced Perl Programming Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
Topic 2: Working with scalars CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 2, pages 19-38, Programming Perl 3rd edition chapter.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
CVS: Concurrent Version System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
8.1 Common Errors – Exercise #3 Assuming something on the variable part of the input file. When parsing a format file (genebank, fasta or any other format),
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.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Perl Scripting III Arrays and Hashes (Also known as Data Structures) Ed Lee & Suzi Lewis Genome Informatics.
Make: File Dependency System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
1 PERL Functions. 2 Functions Functions also called subroutines are “free flowing”. The returned value from a function can be interpreted in many different.
2.1 Lesson 2: Scalar Functions and Arrays “Perl programming is an empirical science!” - Larry Wall.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
BINF 634 Fall LECTURE061 Outline Lab 1 (Quiz 3) Solution Program 2 Scoping Algorithm efficiency Sorting Hashes Review for midterm Quiz 4 Outline.
Programming Perl in UNIX Course Number : CIT 370 Week 2 Prof. Daniel Chen.
File Handle and conditional Lecture 2. File Handling The Files associated with Perl are often text files: e.g. text1.txt Files need to be “opened for.
CSC 4630 Perl 2 adapted from R. E. Beck. I/O and Arithmetic Form pairs of programmer/investigator/discover Exercise 1. Write a program that prompts the.
C Programming Day 2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/LA07/003 Version No. 1.0 Union –mechanism to create user defined data types.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
CSc 110, Autumn 2016 Lecture 26: Sets and Dictionaries
Lecture 2 BNFO 601.
Perl Variables: Array Web Programming.
Perl Variables: Hash Web Programming.
Data Structures – 1D Lists
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
Writing Functions( ) (Part 4)
Introduction to Python
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
Presentation transcript:

Perl Challenge Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National University of Technology (Korea) and NYU

Perl Challenge Prof. Andrzej (AJ) Bieszczad Phone: Exercises #1, #2 Input your name into a variable called $name and then print "Hello, ". my $name; print "Enter your name: "; chomp( $name = ); print "Hello, $name.\n"; Create a subroutine that takes a person's name and prints "Hello,." print "Enter your name: "; chomp( my $name = ); &printName( $name ); sub printName { my $name = $_[0]; print "Hello, $name.\n"; }

Perl Challenge Prof. Andrzej (AJ) Bieszczad Phone: Exercise #3 Write a program that asks a user for five groceries, and then store them (using random access operations) in an array and prints them out in alphabetical order. print "Enter five items from a grocery list:\n"; for( my $i = 0; $i < 5; $i++ ) { print "Enter item $i: "; chomp( $grocerylist[$i] = ); = ); print "\nThe items you entered are:\n"; print ), "\n";

Perl Challenge Prof. Andrzej (AJ) Bieszczad Phone: Exercise #4 Write a program that asks a user for five groceries, but store the groceries into an array using one of the stack operations. (Either push or unshift.) print "Enter five items from a grocery list:\n"; my $input); foreach( 1..5 ) { print "Enter item $_: "; chomp( $input = ); $input ); = ); print "\nThe items you entered are:\n"; print ), "\n";

Perl Challenge Prof. Andrzej (AJ) Bieszczad Phone: Exercise #5 Write a program that uses a subroutine that asks a user for five groceries. After obtaining the list, the program should print the list in alphabetical order. sub input { my $list; for( my $i = 1; $i <=5; $i++ ) { print "Enter grocery $i: "; chomp( my $grocery = ); $grocery ); } } print "Enter five groceries to be sorted and stored in the file \"grocerylist.txt\":\n"; = sort( &input() ); print "\nThe items you entered are:\n"; print ), "\n";

Perl Challenge Prof. Andrzej (AJ) Bieszczad Phone: Exercise #6 Amend program #5 with a subroutine that writes the list of groceries to a file, and then write them to a file in alphabetical order. Modify the input subroutine, so it sorts the list before returning. sub write { my $to_write = join( "\n", ) ); open( OUT, ">grocerylist.txt" ); select OUT; print $to_write; close( OUT ); select STDOUT; } print "Enter five groceries to be sorted and stored in the file \"grocerylist.txt\":\n"; &write( &input() );

Perl Challenge Prof. Andrzej (AJ) Bieszczad Phone: Exercise #7 Write a program that reads the file written in the last exercise, and then prints the contents of the file to the screen in the opposite order that they appeared in the file. sub read { open( IN, $_[0] ); while(my $line = ) { chomp( $line ); $line ); } close( IN ); } print "Opening file grocerylist.txt\n"; print join( "\n", reverse( &read("grocerylist.txt") ) ), "\n";