CS 360 - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

CS 360

Description:

CS 360 Internet Programming Objectives for this class period Web programming is important Administrative organization of the course Introduction to first two labs ... – PowerPoint PPT presentation

Number of Views:74
Avg rating:3.0/5.0
Slides: 27
Provided by: MarkCl1
Learn more at: http://dna.cs.byu.edu
Category:
Tags: mysql

less

Transcript and Presenter's Notes

Title: CS 360


1
CS 360
  • Internet Programming

2
Objectives for this class period
  • Web programming is important
  • Administrative organization of the course
  • Introduction to first two labs
  • Basic Perl

3
Job Postings
  • In terms of specific technologies you should be
    familiar with, you should be comfortable
    programming in Java, PHP, and/or .NET (any, but
    not necessarily all, are desirable). Excellent
    working knowledge of HTML is a must. It would
    also be helpful to have some experience with
    JavaScript, HTTP, and regular expressions.
    Familiarity with other web-related technologies
    such as Active Server Pages and J2EE is helpful.
    You should also have experience working with
    relational databases (e.g., mySQL).

4
Job Postings
  • This full-time or part-time programmer would help
    develop our current web application in
    JavaScript, PHP, MySQL, Flex (a bonus), (minimum
    2 years experience in PHP). We are moving in a
    transition to AJAX and Python for portions of our
    application and knowledge in these areas is a
    bonus.

5
What is CS 360?
  • It gives you the skills you need to apply for
    these jobs
  • It provides you with Operating System
    Fundamentals
  • File Systems
  • Semaphores
  • Sockets
  • You should have a good architectural view of
    internet programming

6
Overview
  • 15 Laboratories will keep you busy
  • Due nearly every week
  • Midterm and Final covering book material
  • Homework
  • Due each Friday
  • Create a web page
  • This class should be a lot of fun!

7
First Lab Due Wednesday
  • Create a web page for homework assignments
  • Make it passwd protected

8
The first real lab is due on Friday
  • Install Apache
  • Write Perl code to test performance
  • You will apply this to your web server in future
    labs
  • This shouldnt be hard, but you need to get
    started now

9
Perl Introduction
  • Uses
  • Shell scripts
  • CGI, web engines
  • Good at
  • Text processing
  • Small/Medium sized projects
  • Quick and dirty solutions
  • Portability (to a certain degree)

10
Perl Introduction
  • Bad at
  • Efficient large scale computation
  • Neat code!

11
Hello World
!/usr/bin/perl This is a comment. It goes to
the end of the line. Perl is easy. It helps to
be neat. Just like C, every statement must end
with print Hello World\n
12
Perl Data Types
  • Three Main Datatypes
  • Scalar
  • A single number, string or reference.
  • sequence acgtac
  • num 6
  • num num 1
  • List
  • A collection of scalar datatypes.
  • _at_insects ( hopper acgtacacactgca,
    flick acgcacacattgca, Catapillar
    acgcatattttgca)
  • insectsnum ant attaccagga
  • Length of an array insects
  • Hash
  • Pairs of scalars, accessed by keys.
  • hash ( Spins gt Atlas, Sings gt
    Goldfish )
  • hashSpins Globe

13
Perl Context
  • Operations may return diferent values, or do
    different things based on the context in which
    they are called.
  • Reading from a filehandle
  • one_line ltFILEHANDLEgt
  • _at_whole_file ltFILEHANDLEgt
  • Removing Newlines
  • chomp(string)
  • chomp(_at_list)

14
Perl Syntax
  • Basic Operators - / -- -
    /
  • String concatenation newstring s . another
    string
  • Numerical operations
  • if(x y) Equality
  • if(x lt y) Less than or Equal to
  • if(x gt y) Greater than
  • String operations (Based on lexial ordering)
  • if (s1 eq s2) Stringwise equality
  • if(s1 gt s2) Stringwise greater than
  • if(s1 le s2) Stringwise less or equal

15
Perl Basics if
  • Selective evaluate blocks of code depending on a
    condition.
  • If (string eq blah)
  • print String is blah\n
  • elsif (string eq spoo)
  • Print String is spoo\n
  • else
  • Print String isnt either?\n

16
Perl Basics - if
  • Can also be done as a one-liner
  • print String is foo\n if (string eq foo)
  • Unless (Not if)
  • print String is not foo\n unless (string eq
    foo)
  • Unless cannot have else or else if components.

17
Perl Basics for
  • Practically the same as C/C/Java
  • for (i 0 i lt 10 i)
  • print i is . i . \n

18
Perl Basics foreach
  • A handy way of processing a list
  • foreach grocery (_at_groceries) scan(grocery)
  • Can use the default variable (_)
  • foreach (_at_groceries) scan(_)

19
Perl Default Variables
  • Most basic functions will operate on the default
    variable by default.
  • foreach (_at_list)
  • chomp
  • print
  • Above chomps each element, and prints it.

20
Perl Basics
  • Command-line arguments
  • Contained in _at_ARGV
  • Strings just like C
  • ARGV0 is not the program name
  • Environment variables
  • Contained in ENV
  • print ENVPATH

21
Perl Basics - Subroutines
  • Identified by keyword sub
  • Arguments come in _at__
  • Local variables identified by keyword my

!/usr/bin/perl t1 1 t2 2 t3
testsubroutine(t1, t2) print "The answer from
testsubroutine is t3\n" sub testsubroutine
my arg1 shift _at__ my arg2
shift Since _ is default variable, we dont
have to type it return arg1 arg2
22
Perl Filehandles
  • An interface to an open file.
  • Line read operator is angle brackets.
  • open(INFILE, dna1.txt) or die cant open
    dna1.txt !
  • while(ltINFILEgt) print line
    _\n
  • ltSTDINgt
  • ltSTDERRgt
  • Opening files in other modes
  • Change the filename string
  • ltdna1.txt read dna1.txt
  • gtdna2.txt output to dna2.txt
  • gtgtdna2.txt append to dna2.txt

23
Perl File Reading Writing
FILE1 ARGV0 FILE2 ARGV1 open(FILE1)
or die "Unable to open FILE1 for
reading\n" open(FILE2, "gt . FILE2) or die
"Unable to open FILE2 for writing\n" while
(ltFILE1gt) print FILE2 _ close(FILE1) cl
ose(FILE2)
24
Running other programs
  • Use back ticks
  • people who
  • Use the system command
  • system(who gt who.dat)
  • Using piped input
  • open(PEOPLE, who )
  • while(ltPEOPLEgt) print _ is
    logged on\n

25
Libwww
  • Dont worry about the CGI in the examples, we
    will get to it later

Create a user agent object use
LWPUserAgent ua LWPUserAgent-gtnew
ua-gtagent("MyApp/0.1 ") Create a request
my req HTTPRequest-gtnew(POST gt
'http//search.cpan.org/search')
req-gtcontent_type('application/x-www-form-urlenco
ded') req-gtcontent('querylibwww-perlmodedis
t') Pass request to the user agent and get
a response back my res ua-gtrequest(req)
Check the outcome of the response if
(res-gtis_success) print res-gtcontent
else print res-gtstatus_line, "\n"

26
This is really easy
  • Practice and work with examples from the web.
  • Look at all of the response elements
  • You will want to use this perl script to debug
    your web server.
Write a Comment
User Comments (0)
About PowerShow.com