INE1020 Introduction to Internet Engineering Tutorial 9 Lab 6 and Assignment 2.
-
Upload
samson-nash -
Category
Documents
-
view
219 -
download
0
Transcript of INE1020 Introduction to Internet Engineering Tutorial 9 Lab 6 and Assignment 2.
INE1020Introduction to Internet
EngineeringTutorial 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
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’.
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)
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”);
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
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
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
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;
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
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
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
Change a string into integer
• You have to change the string into integer before you compare the price
• Use integer = parseInt(string)
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();
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