{\rtf1\ansi\ansicpg1252\uc1 \deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman{\*\falt Thorndale};}{\f2\fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}
{\f29\fswiss\fcharset128\fprq2{\*\panose 020b0604020202020204}Arial Unicode MS;}{\f30\fswiss\fcharset128\fprq2 @Arial Unicode MS;}{\f93\froman\fcharset238\fprq2 Times New Roman CE{\*\falt Thorndale};}
{\f94\froman\fcharset204\fprq2 Times New Roman Cyr{\*\falt Thorndale};}{\f96\froman\fcharset161\fprq2 Times New Roman Greek{\*\falt Thorndale};}{\f97\froman\fcharset162\fprq2 Times New Roman Tur{\*\falt Thorndale};}
{\f98\froman\fcharset177\fprq2 Times New Roman (Hebrew){\*\falt Thorndale};}{\f99\froman\fcharset178\fprq2 Times New Roman (Arabic){\*\falt Thorndale};}{\f100\froman\fcharset186\fprq2 Times New Roman Baltic{\*\falt Thorndale};}
{\f109\fmodern\fcharset238\fprq1 Courier New CE;}{\f110\fmodern\fcharset204\fprq1 Courier New Cyr;}{\f112\fmodern\fcharset161\fprq1 Courier New Greek;}{\f113\fmodern\fcharset162\fprq1 Courier New Tur;}
{\f114\fmodern\fcharset177\fprq1 Courier New (Hebrew);}{\f115\fmodern\fcharset178\fprq1 Courier New (Arabic);}{\f116\fmodern\fcharset186\fprq1 Courier New Baltic;}{\f327\fswiss\fcharset0\fprq2 Arial Unicode MS Western;}
{\f325\fswiss\fcharset238\fprq2 Arial Unicode MS CE;}{\f326\fswiss\fcharset204\fprq2 Arial Unicode MS Cyr;}{\f328\fswiss\fcharset161\fprq2 Arial Unicode MS Greek;}{\f329\fswiss\fcharset162\fprq2 Arial Unicode MS Tur;}
{\f330\fswiss\fcharset177\fprq2 Arial Unicode MS (Hebrew);}{\f331\fswiss\fcharset178\fprq2 Arial Unicode MS (Arabic);}{\f332\fswiss\fcharset186\fprq2 Arial Unicode MS Baltic;}{\f335\fswiss\fcharset0\fprq2 @Arial Unicode MS Western;}
{\f333\fswiss\fcharset238\fprq2 @Arial Unicode MS CE;}{\f334\fswiss\fcharset204\fprq2 @Arial Unicode MS Cyr;}{\f336\fswiss\fcharset161\fprq2 @Arial Unicode MS Greek;}{\f337\fswiss\fcharset162\fprq2 @Arial Unicode MS Tur;}
{\f338\fswiss\fcharset177\fprq2 @Arial Unicode MS (Hebrew);}{\f339\fswiss\fcharset178\fprq2 @Arial Unicode MS (Arabic);}{\f340\fswiss\fcharset186\fprq2 @Arial Unicode MS Baltic;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;
\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;
\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\ql \li0\ri0\widctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 Normal;}{\*\cs10 \additive Default Paragraph Font;}{
\s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 \fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 \snext15 Default;}{\s16\ql \li0\ri0\nowidctlpar\tqc\tx4320\tqr\tx8640\aspalpha\faauto\rin0\lin0\itap0 
\fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 \sbasedon15 \snext16 header;}{\*\cs17 \additive \fs24\cf1\lang0\langfe255\langfenp255 Numbering Symbols;}}{\info{\author Sharon Tuttle}{\operator CNRS}{\creatim\yr2004\mo8\dy2\hr14\min32}
{\revtim\yr2004\mo9\dy29\hr23\min34}{\printim\yr2004\mo9\dy9\hr10\min40}{\version5}{\edmins4}{\nofpages2}{\nofwords756}{\nofchars4310}{\*\company CNRS-HSU}{\nofcharsws5292}{\vern8269}}\margt2079 
\deftab1250\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\horzdoc\dghspace120\dgvspace120\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind1\viewscale75\nolnhtadjtbl \fet0\sectd 
\sbknone\linex0\headery1440\sectdefaultcl {\header \pard\plain \s16\ql \li0\ri0\nowidctlpar\tqc\tx4320\tqr\tx8640\aspalpha\faauto\rin0\lin0\itap0 \fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 {\fs16 
CIS 480 -  Homework #3 and Week 3 Lab Exercise \tab \tab p. }{\field{\*\fldinst {\fs16 \\page}}{\fldrslt {\fs16\lang1024\langfe1024\noproof 2}}}{
\par }{\fs16 Fall 2004
\par }}{\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta )}}
{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl8
\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}\pard\plain \s15\qc \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 
\fs24\cf1\lang1033\langfe255\cgrid\langnp1033\langfenp255 {\b\fs22 CIS 480 - Perl in Depth - Fall 2004
\par WEEK 6 LAB EXERCISE and Homework #5
\par 
\par week 6 lab exercise due: Thursday,  September 30th , END of lab
\par }\pard \s15\qc \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22 HW #5 due: Thursday, October 7th, 12:00 noon
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {\fs22 ---------------------------------------------------------------------------------------------------------
\par For }{\b\fs22 EACH}{\fs22  of the scripts below (lab exercise AND homework), you are required to begin EACH with the following:
\par }{\fs20 
\par }{\fs20\loch\af2 \hich\af0\dbch\af0\loch\f2 #!/usr/bin/perl -w
\par \hich\af0\dbch\af0\loch\f2 ###480-author: }{\i\fs20\loch\af2 \hich\af0\dbch\af0\loch\f2 yourLastName}{\fs20\loch\af2 
\par \hich\af0\dbch\af0\loch\f2 ###480-scriptname:\hich\af0\dbch\af0\loch\f2  }{\i\fs20\loch\af2 \hich\af0\dbch\af0\loch\f2 yourScriptName}{\fs20\loch\af2 
\par }{\i\fs20\loch\af2 
\par \hich\af0\dbch\af0\loch\f2 (}{\i\fs28\loch\af2 \hich\af0\dbch\af0\loch\f2 THEN}{\i\fs20\loch\af2 \hich\af0\dbch\af0\loch\f2  an }{\i\fs20\ul\loch\af2 \hich\af0\dbch\af0\loch\f2 opening comment block }{\i\fs20\loch\af2 \hich\af0\dbch\af0\loch\f2 
containing the NAME of the script file, your name, the date, and a brief description of the purpose of this script)
\par 
\par }{\fs22 Note that the spacing and header need to be exact --- I hope to develop a Perl script to process these in some interesting and useful fashion. More on that as it develops.
\par --------------------------------------------------------------------------------------------------------
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22\ul WEEK 6 LAB EXERCISE
\par }{\b\fs20\ul 
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22 1.\tab }{\fs22 Write a Perl script }{\b\fs22 simple_replace}{\fs22 
: Ask the user to enter a filename, a string to be replaced in that file, the string to replace that string with, and the filename to write the results to --- then perform that replacement, putting
 all of the lines of the input file into the output file but with the requested string replaced with the requested replacement. Complain and die if input filename user enters does not exist; warn but don't die if output filename user enters already exists
 (warn, then merrily nuke it...)
\par }{\b\fs22 
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {\fs22 When you are done, read this script into a single e-mail message with the Subject: line }{\b\fs22 480 lab 6 }{\fs22 (}{\b\fs22 NO ATTACHMENTS}{\fs22 ), and e-mail them to }{
\b\fs22 st10@humboldt.edu}{\fs22  by the }{\b\fs22 end}{\fs22  of }{\b\fs22 today's}{\fs22  lab.}{\b\fs22 
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22\ul 
\par HOMEWORK #5
\par 
\par }{\b\fs22 1.\tab }{\fs22 Every month, you receive a directory of ASCII files containing data that is to be added to a project database. Unfortunately, the files are named with the suffix }{\f2\fs22 .fict}{\fs22 
, and each row's data is delimited (separated) by asterisks (*). Your database's import tool only accepts files named with the suffix }{\f2\fs22 .norm}{\fs22 , containing rows of data delimited by semicolons (;).
\par 
\par \tab Sure, every month you could change the name of each file in the directory, open each, and do a manual search-and-replace --- but why, when you have the power of Perl at your fingertips? 
\par 
\par \tab Write a Perl script }{\b\fs22 convert_to_norm}{\fs22  that expects to be called from within a directory containing }{\f2\fs22 .fict}{\fs22  files. It then creates a }{\f2\fs22 .norm}{\fs22  file for each }{\f2\fs22 .fict}{\fs22 
 file in that directory, such that every * in the }{\f2\fs22 .fict}{\fs22  file is now a ; in the }{\f2\fs22 .norm}{\fs22  version.
\par }{\b\fs22 
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22 2.\tab }{\fs22 Write a Perl script }{\b\fs22 pref_count}{\fs22 
: Ask the user to choose their favorite from a list of at least 8 numbered options (whatever topic you'd like) --- whatever option number he/she chooses, you have a separate counter file for that o
ption, and you should increment the value in that option's counter file whenever a user chooses that option. Then you should print a message to the screen thanking the user for his/her vote, including how many (including this latest voter) have selected t
he chosen option.}{\b\fs22 
\par 
\par \tab }{\fs22 Some additional requirements:
\par }\pard \s15\ql \fi-435\li855\ri0\nowidctlpar\aspalpha\faauto\rin0\lin855\itap0 {\fs22 *\tab 
your script should not accept an option number other than those it shows --- it should loop, making the user try again until he/she enters one of the given option numbers.
\par 
\par *\tab I know good and well that some
 of you would attempt this with at least one big long if-elsif-else chain and a few chunklets of quite-repetitive code if I didn't somehow forbid it. (Why? Because, OK, I confess, that's what I did in my first version...) But that is ugly because it is un
necessary thanks to Perl hashes. (Yes, because this problem uses option numbers, arrays could work, too. But you are required to use hashes anyway.)
\par 
\par \tab Your solution must use at least two hashes to avoid such big long if-elsif-else's (and at least two chunklets of 8 or more extremely repetitive statements...!): 
\par }\pard \s15\ql \fi-435\li1290\ri0\nowidctlpar\aspalpha\faauto\rin0\lin1290\itap0 {\fs22 *\tab one hash will link an option number to the text for that option,
\par *\tab the other hash will link an option number to the name of the counter file for that option.
\par 
\par }\pard \s15\ql \fi-435\li855\ri0\nowidctlpar\aspalpha\faauto\rin0\lin855\itap0 {\fs22 \tab That, and remembering the lovely hash function exists, should lead you to a more elegant solution. 
\par }{\b\fs22 
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22 3.\tab }{\fs22 But, after #2, something feels not quite finished, doesn't it? We need a way to simply see the current vote totals, don't we?}{\b\fs22 
\par 
\par \tab }{\fs22 Write a perl script }{\b\fs22 pref_results}{\fs22  that shows the votes for each option on the screen in a pleasant fashion. Copy both of your hashes from #2 into this new script for use in this new script.
\par 
\par \tab And, to make things a little more interesting, use printf to print these results nicely:
\par }\pard \s15\ql \fi-435\li855\ri0\nowidctlpar\aspalpha\faauto\rin0\lin855\itap0 {\fs22 *\tab right-justifying the option numbers,
\par *\tab left-justifying the text for the options,
\par *\tab and right-justifying the vote totals.
\par }{\b\fs22 
\par }\pard \s15\ql \fi-435\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\fs22 \tab 
(Hopefully, you can see even further potential for abstraction to more general tools here --- converting these to read the options and counter file names from a file ins
tead of hard-coding them in, writing a script that builds such a file for a user entering options interactively, and more. But we'll stop here for this homework.)}{\b\fs22 
\par 
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {\fs22 When you are done, read all of these scripts  into a single e-mail message with the Subject:
 line 480 hw 5 (NO ATTACHMENTS), and e-mail them to st10@humboldt.edu by the due date and time given above.
\par 
\par (remember, you can use ^R within your properly-configured pine on cs-server to copy a file's contents reliably into an e-mail message.)
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs20 
\par }}