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

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

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

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

INE1020Introduction to Internet

EngineeringTutorial 9

Lab 6 and Assignment 2

Page 2: INE1020 Introduction to Internet Engineering Tutorial 9 Lab 6 and Assignment 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

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

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’.

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

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 <FILE>, perl will read the file line by line and store the data into the variable $_

• Remember to close the file by close(FILE)

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

Perl: How the split the words in a string

• @data = split(/a/, $string_to_split);– $string_to_split is the variable containing a lon

g 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”);

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

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

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

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

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

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

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

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;

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

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

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

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

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

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 ‘te

xt’, ‘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

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

Change a string into integer

• You have to change the string into integer before you compare the price

• Use integer = parseInt(string)

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

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();

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

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