Lab 7: Perl Filter Solution

$30.00 $24.00

Quantity

You'll get a: . zip file solution : immediately, after Payment

Description

Introduction

Lab 7 is the first and simplest Perl script that filters data presented on STDIN, changing all occurrences of a FROMSTRING string to a TOSTRING and outputting all input lines, changed and unchanged to STDOUT. FROMSTRING and TOSTRING can be ordinary text or PERL-compatible regular expressions.

Requirements

Your Perl script shall be named filter.pl and be marked executable.

Usage: ./filter.pl ‘FROMSTRING’ ‘TOSTRING’

Example, where we read SOMEFILE and change all occurrences of FOO to BAR

cat SOMEFILE | ./filter.pl ‘FOO’ ‘BAR’

Your script should read only from STDIN and write only to STDOUT. Write error messages only to STDERR. Your script should never prompt the user or open any files.

Your script should support regular expressions and be capable of changing all occurrences of the FROMSTRING to TOSTRING . All lines are output, both changed and unchanged. exit(0) if there are no errors. It is ok for nothing on the input to be changed as they are output.

Issue a Usage message and exit(1) if there are not exactly two commandline parameters provided.

Helpful Hints

Use /usr/bin/perl on icarus as your “shebang”. use while (<STDIN>) to read each line of input Use $_ to access each line read

use s/// (the substitution operator) to change all occurrences of FROMSTRING to TOSTRING on each line

Use print to output all line on STDIN to STDOUT, whether or not the line was changed

$ARGV[] contains the commandline arguments. For example, $ARGV[0] is the first argument,

FROMSTRING

$#ARGV is the index of the last item in $ARGV

s/$ARGV[0]/eval qq(“$ARGV[1]”)/ge;

Clone your private repo on github.com

In the assignment module in Canvas, find the link to the Canvas page entitled “Clone your Lab 7 Repo”, click on it and follow the instructions.

Copy your private repo down to icarus

BASH

git clone https://github.com/cowancs3030spring19/lab7-YOURGITHUBUSERNAME

cd lab7-YOURGITHUBUSERNAME

Write and test filter.pl

Fire up your favorite text editor, and update the header:

#!/usr/bin/perl

TEXT

• (Your name)

• Lab 7 – Perl Filter

• CS 3030 – Scripting Languages

(add your unbelievably elegant code here)

Run cucumber to check your progress

./cucumber -s

Submit your assignment code for grading

• Remember, you must push your script in your private repo to github.com to receive any points, for all assignments in this course.

BASH

git add filter.pl

git commit -m”COMMIT MESSAGE”

git push origin master

Files changed for this lab

filter.pl

Grading

Here is how you earn points for this assignment:

FEATURES
POINTS

Must-Have Features

Script is named correctly and found in its proper place in your private repo
5

Script is executable
5

Required Features

Script prints a “Usage:” statement and exits rc=1 if there are not exactly two
5

commandline parameters

Script exits rc=0 on successful completion
5

Script reads from STDIN
10

Script writes to STDOUT unless error
10

Script writes error messages only to STDERR
10

Script properly translates the input to the output using a simple string replacement
10

Script supports regular expressions in FROMSTRING
20

Script supports regular expressions in FROMSTRING and TOSTRING
20

Grand Total
100

0