Scripting language programming in perl

Assignment Help Programming Languages
Reference no: EM1342611

Scripting Language Programming, Assignment  Perl 

General Requirements

? Your coding style should conform to general Perl coding conventions. Your scripts should be clean, neat, and well-formatted (e.g. indention). Identifiers should also be properly named.

? Your scripts should be well-documented by using POD so users can easily understand your scripts and their usage by exporting POD as HTML, plain text or LaTeX.

? You should always properly validate data inputs (including command-line arguments) and display user-friendly error messages where applicable. For example, if a script is expecting only one argument which specifies a file, you should validate:

ü There is only one command line argument (or you should display the 'usage');

ü The specified argument is a file and is accessible.

Depending on what the script does, you should also make other reasonable validations, e.g., whether a specified directory is valid and accessible.

? If a standard output format is not specified, you are free to make your own assumptions so long as your output displays all required information and is in a neat and user-friendly format.

? Any standard Perl modules shipped with Perl 5.10 may be used. However, you should not use any module which is not available on RMIT CSIT Core Teaching Linux servers.

? If you fail to meet the aforementioned general requirements, you may lose up to 25% of marks available in each part of this assignment.

? You must attempt each part of this assignment progressively. For example, if you attempt Part D without first completing Part C, you will not get any marks for Part D.

 

Part A: Perl Script Analyser (PartA.pl)

Write a Perl script to analyse another Perl script specified as the first command-line argument.

As part of pre-analysis validations, your script should check if the specified script file:

  • ? has an acceptable file extension (defined below); and
  • ? exists; and
  • ? is a readable text file; and
  • ? is not empty.

Acceptable file extensions are (case sensitive):

  • ? .pl
  • ? .pm

Your script should display the following error message and quit gracefully if the specified file failed any one (or more) of the pre-analysis validations:

[user@csitprdap01 ~]$ ./PartA.pl /aaa/bbb/ccc/invalid_script.pl

Error: unable to analyse the specified file.

[user@csitprdap01 ~]$

It is important that you display the exact same error message as your assignment submission may be assessed by an automated marking process.

Once a script file passed the pre-analysis validation, your script should perform the following tasks in order:

? Display the number of lines, words, and characters in the file based on the output of an external Linux command of your choice, e.g. wc;

? Identify the keywords in the script, and display them in the order as they first appeared in the file. If a keyword appeared multiple times in the script, only the first instance should be displayed. If there are more than 15 unique keywords in the file, display the first 15 keywords only;

? Identify the strings in the script, and display them in the order as they appeared in the file. If there are more than 10 strings in the file, display the first 10 strings only;

? Identify the comments in the script, and display them in the order as they appeared in the file. If there are more than 5 comments in the file, display the first 5 comments only.

For the purpose of this assignment:

? a keyword is a Perl function keyword, a Perl syntax keyword or a File Handles keyword listed on https://learn.perl.org/docs/keywords.html;

? a string always have single quotes or double quotes around them;

? a comment is the text from a # character until the end of the line, unless the # character is inside a string or a regular expression.

For the purpose of Part A only, we assume:

? keywords appeared in strings and comments are still considered keywords;

? a string is always on the same line, i.e. you do not need to consider multi-line strings;

? # characters do not appear inside strings or regular expressions;

? single or double quoted strings do not appear in comments.

To demonstrate the output format, we use the following sample script file hello.pl:

#!/usr/bin/env perl

use strict;

use warnings;

# assign variable

my $string = 'Hello World!';

# display value

print "$string\n";

The following output from PartA.pl is expected:

[user@csitprdap01 ~]$ ./PartA.pl /home/el2/eXXXXX/scripts/hello.pl

File: hello.pl

Lines: 8

Words: 19

Chars: 129

[Keywords]

use

my

print

[Strings]

'Hello World'

"$string\n"

[Comments]

# assign variable

# display value

[user@csitprdap01 ~]$

It is important that you display the results in the exact same sequence and format as your assignment submission may be assessed by an automated marking process.

 

This sample script and the expected output will be published in the Blackboard so you can compare if your script is producing an exact identical outcome. Please note this is only for the purpose of hecking output format. To verify if you have implemented the script correctly, you are expected to create more complex test cases yourself. 

Part B: Improved Perl Script Analyser (PartB.pl)

Based on your PartA.pl, create a new script PartB.pl.

This new script should perform the same tasks as Part A but WITHOUT using any external command. It is also important to note that the assumptions (in the last paragraph on Page 2) for Part A is no longer valid in Part B. Therefore, in Part B:

? keywords appeared in strings and comments are not considered keywords;

? strings may appear on multiple lines, but they always have single quotes or double quotes around them;

? # characters may appear inside strings or regular expressions;

? single or double quoted strings may appear in comments.

Part C: Advanced Perl Script Analyser (PartC.pl)

Based on your PartB.pl, create a new script PartC.pl.

In addition to the existing features of Part B, you should also identify the numbers in the script using Regular Expressions, and display them in the order as they appeared in the file. If there are more than 10 numbers in the file, display the first 10 numbers only. The identified numbers should be displayed after the keywords section but before the strings section.

For the purpose of this assignment:

? a number is a Perl numeric literal in any of the floating point or integer formats specified on https://perldoc.perl.org/perldata.html#Scalar-value-constructors except those within strings or comments.

A sample script and the expected output for Part C will be published in the Blackboard. 

Part D: Perl Script Syntax Highlighter (PartD.pl)

PartD.pl accepts two command line arguments, the Perl script to be syntax highlighted, and then an HTML output filename (with the file extension of either .htm or .html). The script should not produce any output to the screen unless there is an error. If the output file already exists, it will be overwritten.

The title of the generated HTML file should be the file name of the specified script.

The following HTML colour codes should be used to syntax highlight the Perl script in the HTML output:

? Keywords - darkred

? Numbers - darkcyan

? Strings - royalblue

? Comments - darkgreen

To maintain the format and readability, the entire script should be wrapped within a pair of HTML <pre> tags.

Reference no: EM1342611

Questions Cloud

Show the dimensions of cultural differences : Which of these differences has the largest effect on employee behavior and how can you develop training that motivates learning and incorporates the different learning styles of the trainees
Disclose what the book suggests : Disclose what the book suggests once the short-term rate is much cheaper than the long-term in interest rate. Substantiate whether or not that is a normal occurrence or a cause for alarm.
Recent change in us business : Could you help me in identifying one recent change in US businesses for economic
Difference to valuation by us gaap vs ifrs : Difference to valuation by US GAAP vs IFRS- Apple Philips and Is there a difference in approach to valuation by US GAAP and IFRS?
Scripting language programming in perl : course Scripting Language Programming,  Assignment   -  Perl,  ? Your coding style should conform to general Perl coding conventions. Your scripts should be clean, neat, and well-formatted (e.g. indention). Identifiers should also be properly name..
Explain about workforce benefit an organization : Diversity in the workplace - How does cultural and racial diversity in the workforce benefit an organization?
Preparing a presentation for a diverse group of employees : Ensure that you consider issues such as arrangement of the room, content and length of the presentation, and handouts and visual aids
Example of revenue resulting in a temporary difference : Example of revenue resulting in a temporary difference - Can you give a specific example of revenue that might result in a temporary difference?
Show cultural differences in alliance teams : Explain what can be done to prevent cross-cultural problems and unmet expectations from keeping an alliance team from being effective

Reviews

Write a Review

 

Programming Languages Questions & Answers

  Application development and programming languages

Application Development and Programming Languages,  Programming languages have evolved since the First Generation Languages (1GLs) in the 1940s. The 1GLs were machine languages, which interacted directly with hardware. 2GLs were assembly languages. F..

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Explain about lexical analyzer

Explain about Lexical Analyzer

  Communicate with a pc using the rs232c serial protocol

In this assignment we will use the UART0 peripheral to communicate with a PC using the RS232C serial protocol.

  Create a multi-threaded competition

Create a multi-threaded competition in which opposing Robin Hoods will attack one another and try to take each other's gold coins.

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Technical project: sample website project

Technical Project: Sample Website Project , This assignment consists of three (3) sections: a narrative, a storyboard, and a business Website. You must submit all three (3) sections for the completion of this assignment.

  Write a program using binary search approach

Write a program using binary search approach

  Show how the tree might be type-checked

Attempt to derive proof tree for the judgment Show how the tree might be type-checked

  Write pseudocode

Write pseudocode that represents the abstract functions of the enqueue and dequeue operations. Define and explain any supplementary information needed by your pseudocode.

  Create a simple shell

Create a simple shell. Basically your shell should read the line from standard input, parse the line with command and arguments, and operate the command with arguments.

  Writing a class

Build a class for a type called Fraction

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