Presentation is loading. Please wait.

Presentation is loading. Please wait.

INE1020 Introduction to Internet Engineering Tutorial 9 Lab 6 and Assignment 2.

Similar presentations


Presentation on theme: "INE1020 Introduction to Internet Engineering Tutorial 9 Lab 6 and Assignment 2."— Presentation transcript:

1 INE1020 Introduction to Internet Engineering Tutorial 9 Lab 6 and Assignment 2

2 Perl: Different variable type Perl has different variable type which can be distinguished by the first symbol –$ means scalar variable –@ means array/list –% means hash Remember to being a variable with these symbol

3 Perl: How to read an input from a web page? my $username = param(USERNAME); $username is the variable name used in the whole perl scripts USERNAME is the name of the input inside a form. It can be a ‘text’, ‘radio’, ‘password’ or ‘select’.

4 Perl: How to read the data in a file? open(FILE, "data.txt") –FILE is the handle used in the script –data.txt is the file name Use, perl will read the file line by line and store the data into the variable $_ Remember to close the file by close(FILE)

5 Perl: How the split the words in a string @data = split(/a/, $string_to_split); –$string_to_split is the variable containing a long string –‘a’ is the pattern where the string should split –@data contain the data after splitting E.g “This is a string”, and split by /i/, then @data=(“Th”, “s “, “s a str”, “ng”);

6 Perl: Subroutines ‘sub access’ is a subroutine –All subroutine should be started with ‘sub’ –‘access’ is the name of the subroutine To run a subroutine, use &sub_name

7 Perl modules Perl has many developed modules to be used In lab 6, the Net::SMTP modules is used This module provides all functions that need to send a email

8 Perl: How to use the Net::SMTP? $smtp = Net::SMTP->new($mailserver); $mailserver should contain the mail server address. If the mail server cannot be opened, $smtp will be null

9 Perl: How to use Net::SMTP? To send a email –$smtp->mail($ENV{USER}); –$smtp->to("$to"); –$smtp->data(); –$smtp->datasend("To: $to \n"); –$smtp->datasend("From: $from \n"); –$smtp->datasend("Subject: $subject \n"); –$smtp->datasend("\n"); –$smtp->datasend("$message \n"); –$smtp->dataend(); –$smtp->quit;

10 Assignment 2: Basic architecture 6 files needed if frame is not used 5 html files which each contains the details of one product 1 html file which contains the form and the JavaScript When the search button is pressed, a JavaScript function is called instead of a new web pages is loaded

11 Assignment 2: Use array to store the data Use a two-dimensional array to store the search data Since 5 products is required and each product has 4 fields. The array size should be 5x4

12 How to read an input field in JavaScript? Use document.form.field.value –‘form’ is the name of the form –‘field’ is the name of a field, which can be a ‘text’, ‘password’ or ‘select’ To read which radio button is selected, use document.form.radio.checked If the button is checked, the above statement will return true. So you have to check the radio button one by one

13 Change a string into integer You have to change the string into integer before you compare the price Use integer = parseInt(string)

14 Write the output into a new window To open a new window –new_win = window.open(); To start writing a document –new_win.documnt.open(“text/html”); To write a string to the new window –new_win.document.writeln(); To close the document –new_window.document.close();

15 What should be included in the documentation? The file structure of your web pages What can be searched in your search engine The improvement you have made


Download ppt "INE1020 Introduction to Internet Engineering Tutorial 9 Lab 6 and Assignment 2."

Similar presentations


Ads by Google