Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 360 Internet Programming. Objectives for this class period Web programming is important Administrative organization of the course Introduction to first.

Similar presentations


Presentation on theme: "CS 360 Internet Programming. Objectives for this class period Web programming is important Administrative organization of the course Introduction to first."— Presentation transcript:

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 shouldn’t 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. @insects = ( “hopper acgtacacactgca”, “flick acgcacacattgca”, “Catapillar acgcatattttgca”); $insects[$num] = “ant attaccagga”; Length of an array $#insects” Hash Pairs of scalars, accessed by keys. %hash = ( “Spins” => “Atlas”, “Sings” => “Goldfish” ); $hash{“Spins”} = “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 = ; @whole_file = ; Removing Newlines chomp($string); chomp(@list);

14 Perl Syntax Basic Operators: + - * / ++ -- *= += -= /= String concatenation: $newstring = $s. “another string”; Numerical operations if($x == $y)Equality if($x <= $y)Less than or Equal to if($x > $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 < 10; $i++) { print “i is “. $i. “\n”; }

18 Perl Basics – ‘foreach’ A handy way of processing a list foreach $grocery (@groceries) { scan($grocery); } Can use the default variable ($_) foreach (@groceries) { scan($_); }

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

20 Perl Basics Command-line arguments Contained in @ARGV Strings just like C $ARGV[0] is not the program name Environment variables Contained in %ENV print $ENV{“PATH”};

21 Perl Basics - Subroutines Identified by keyword “sub” Arguments come in @_ 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 @_; my $arg2 = shift;#Since _ is default variable, we don’t 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( ) { print “line $_\n”; } Opening files in other modes Change the filename string “<dna1.txt”read dna1.txt “>dna2.txt”output to dna2.txt “>>dna2.txt”append to dna2.txt

23 Perl File Reading & Writing $FILE1 = $ARGV[0]; $FILE2 = $ARGV[1]; open(FILE1) or die "Unable to open $FILE1 for reading\n"; open(FILE2, ">”. $FILE2) or die "Unable to open $FILE2 for writing\n"; while ( ) { print FILE2 $_; } close(FILE1); close(FILE2);

24 Running other programs Use back ticks $people = `who`; Use the system command system(“who > who.dat”); Using piped input open(PEOPLE, “who |”); while( ) { print “$_ is logged on\n”; }

25 Libwww Don’t worry about the CGI in the examples, we will get to it later # Create a user agent object use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); # Create a request my $req = HTTP::Request->new(POST => 'http://search.cpan.org/search'); $req->content_type('application/x-www-form-urlencoded'); $req->content('query=libwww-perl&mode=dist'); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ($res->is_success) { print $res->content; } else { print $res->status_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.


Download ppt "CS 360 Internet Programming. Objectives for this class period Web programming is important Administrative organization of the course Introduction to first."

Similar presentations


Ads by Google