Cookies management with perl, Programming Languages

Assignment Help:

One of the main strengths of the Perl programming language are its powerful text manipulation features. In this assignment, you will put them to use for writing a Perl program that canmanage a simplified version of the so-called "browser cookies".

These are the specifications for your Perl program:

1. The file with your program must be named cookiemgr.pl

2. The program must be invoked as:

cookiemgr.pl cookies_file [options]

The program must check that its first argument exists, is a file and is readable. If not, it must print string:

Error: a valid file must be passed as first argument

To the standard output, and exit. The first argument is compulsory while the following arguments are optional. The arguments are described in the following.

3. File cookies_file can have any arbitrary name. It must be a file of text with the followingformat:

a. The file consists of an arbitrary number of lines (including, possibly, zero lines).

b. Each line must contain four fields separated by commas.

c. The four fields are: cookie name, cookie value, hostname and expiry date.

d. The first three fields are strings of arbitrary (yet reasonably limited) length; thecharacters in these strings can be any of: uppercase letters, lowercase letters,decimal digits, the underscore and the dot.

e. The expiry date field is a string of decimal digits in the so-called Unix epochformat.

The following example is the ultimate specification for the format of file cookies_file:

SessionID,029380,xyz.org.au,1385874000

ASPX_ANONYMOUS,CjnjrB,xyz.org.au,1356912000

SESSION_COLOUR,red,nosite.com.au,1341014400

SESSION_ACTIVE,FALSE,nosite.com.au,1341014400

username001,massimo.piccardi,hello.uts.edu.au,2145830400

username012,john.smith,hello.uts.edu.au,2145830400

username013,michael.zhang,hello.uts.edu.au,2145830400

Important note: your program does not need to verify that file cookies_filecomplies with the format specifications. You can simply assume that the file meets all the specifications given abov.

 Your program can be invoked without any options. In this case, it must only print thefollowing string:

Found cookies

Example with the example cookies_filegiven above:

Command line:

cookiemgr.pl cookies_file

Output:

Found 7 cookies

In the case in which file cookies_fileis empty, your program must instead only print:

No cookies found

5. Your program can be invoked with option: -h hostname. In this case, it must only print thefollowing string:

Found cookies for host

Example with the example cookies_filegiven above:

Command line:

cookiemgr.pl cookies_file-h nosite.com.au

Output:

Found 2 cookies for host nosite.com.au

Option -h hostname can only be used once per command line (you can only ask for thecookies of one host at a time).

In the case in which file cookies_filecontains no cookies for the given hostname, your program must instead only print:

No cookies found for host

Example with the example cookies_filegiven above:

Command line:

cookiemgr.pl cookies_file-h feit.uts.edu.au

Output:

No cookies found for host feit.uts.edu.au

 Your program can be invoked with option: -d date, where date is entered in dd/mm/yyyyformat. In this case, it must only print the following string:

Found cookies expiring before or on

format>

To find the cookies expiring before, or on, the date given in the option, your program must  convert this date to the Unix epoch format and compare it with the dates stored in cookies_file. The time of the date is always set to be midnight (i.e. 0 hours, 0 minutes, 0 seconds). Perl has functions for converting a date to the Unix epoch format.

Example with the example cookies_filegiven above:

Command line:

cookiemgr.pl cookies_file-d 31/12/2012

The Unix epoch format for 31/12/2012, midnight, is 1356912000. In file cookies_filethereare three dates which are smaller or equal than 1356912000. Therefore, the output must be:

Found 3 cookies expiring before or on 31/12/2012

Option -d date can only be used once per command line (you can only ask for the cookies  for a given date at a time).

In the case in which file cookies_filecontains no cookies expiring before or on the given       date, your program must instead only print:

No cookies found expiring before or on

Example with the example cookies_filegiven above:

Command line:

cookiemgr.pl cookies_file-u 31/05/2010

The Unix epoch format for 31/05/2010, midnight, is 1275264000. In file cookies_filethere   are no dates which are smaller or equal than 1275264000. Therefore, the output must be:

No cookies found expiring before or on 31/05/2010

Your program can be invoked with option: -s. In this case, it must only print your name,surname and student ID in a format of your choice.

The options cannot be used simultaneously. This means that your program can only beinvoked in the following way: 1) with no options; 2) with option -u username; 3) withoption -d date; 4) with option -s.

If your program is invoked with a valid first argument, but any other syntax than whatspecified above, it must only print the following string to the standard output:

Invalid syntax/options

Example:

Command line:

cookiemgr.pl cookies_fileUTS.txt -v

Output:

Invalid syntax/options


Related Discussions:- Cookies management with perl

Code html and xml, Topic Develop a Web site that will provide informat...

Topic Develop a Web site that will provide information about your organization. The Web site will need to have a user-friendly interface for users to enter their information;

Program to calculate the triangle area, Write a program that will allow the...

Write a program that will allow the user to input the corners of a triangle. The program will draw small yellow circles for each input point, then draw the triangle and calculate t

JUnit test, hi, can you help me with testing java classes I have wrote usin...

hi, can you help me with testing java classes I have wrote using java and jsp and servlet in eclipse ? I want to use JUnit for testing

C++, You are to write a program which will answer a pair of questions for s...

You are to write a program which will answer a pair of questions for squares, triangles, circles and ellipses. A square is defined by its lower left corner (SLLx,SLLy), and the len

Pascal, how do i make a bomber game using pascal on a software called lazur...

how do i make a bomber game using pascal on a software called lazuras

We need advancement in existing phonegap application, We need Advancement i...

We need Advancement in Existing PhoneGap Application We need a PhoneGap expert to aid us extend an existing PhoneGap application. The app works pulls data from a new website (de

Pseudo code, I need help putting this into a flowchart constant c as Intege...

I need help putting this into a flowchart constant c as Integer = 3500 Constant CALORIESTOOUNCE as Integer = 219 Declare Sex as Character Declare Age as Integer Declare Weight as I

Implement a two-dimensional table in prolog, Implement a two-dimensional ta...

Implement a two-dimensional table in Prolog. Your program will contain: An insert_entry predicate that takes a table, row, column and an entry and inserts the entry at the g

What is an authentication subsystem, Question: (i) All Security authen...

Question: (i) All Security authentication mechanism that run on the TRU64 Unix Operating system run under the Security Integration Architecture (SIA ) layer. Explain with di

Reader-writer problem, The reader-writer problem can be stated as follows: ...

The reader-writer problem can be stated as follows: A shared memory location can be concurrently read by any number of tasks, but when a task must write to the shared memory locati

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd