Lec7Handouts - CS2044 - Advanced Unix Tools Spring 2009...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CS2044 - Advanced Unix Tools Spring 2009 Lecture 7 David Slater dms236 at cornell.edu March 4, 2009 David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Organization Homework 2 Due Monday March 8th Start Early! Turn In Code That Works! Follow Directions David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 2
Lets talk about homework 1 Homework 1 See CMS David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Perl! Perl is an acronym, short for Practical Extraction and Report Language. It was designed by Larry Wall as a tool for writing programs in the UNIX environment. Why Perl? Perl has the power and flexibility of high level languages like C Like shell scripting, Perl does not require a special compiler and linker to use. This makes Perl ideal for producing quick solutions to small programming problems. Perl provides all the features of sed and awk plus features not found in either. In short, Perl is as powerful as C but as convenient as awk, sed and shell scripting. David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 4
How to write Perl Scripts By convention, we will use the .pl extension for our perl scripts ( foo.pl ) To invoke the Perl interpreter we can type perl foo.pl Or we can start our script with the special character #! followed by where to find perl Perl is usually at /bin/perl (cygwin), /usr/bin/perl (ubuntu and csug machines) or /usr/bin/local/perl . We can also run perl commands directly by typing perl -e ’cmds’ . David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Baby Tiny Simple Silly Perl Scripts #! /usr/bin/perl # babyperl.pl $inputline = <STDIN>; print $inputline; $ ./babyperl.pl Here is my line of text Here is my line of text #! /usr/bin/perl # hello.pl print "Hello World!\n"; $ ./hello.pl Hello World! $ David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 6
Perl Basics A Perl script is a sequence of statements (each statement is one task for the Perl interpreter to perform. Perl programming is not shell programming. You cannot use shell commands in Perl scripts (directly). Comments go anywhere and begin with a # Perl does not care about whitespace and new lines, all of these are equivalent $input=5; $input = 5; $input = 5 ; $input = 5 ; David Slater dms236 at cornell.edu CS2044 - Advanced Unix Tools
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Perl recognizes three types of values: integers, strings and objects (we won’t deal with objects) We can write strings using either single or double quotes A string in single quotes is taken to mean exactly what it is a string in double-quotes is first interpreted (similar to with bash scripting) scalar variables in Perl can be integers and strings and are required to start with the $ character (different from shell scripting!). $i = 10;
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 35

Lec7Handouts - CS2044 - Advanced Unix Tools Spring 2009...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online