{\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;}{\f101\froman\fcharset238\fprq2 Times New Roman CE{\*\falt Thorndale};}
{\f102\froman\fcharset204\fprq2 Times New Roman Cyr{\*\falt Thorndale};}{\f104\froman\fcharset161\fprq2 Times New Roman Greek{\*\falt Thorndale};}{\f105\froman\fcharset162\fprq2 Times New Roman Tur{\*\falt Thorndale};}
{\f106\froman\fcharset177\fprq2 Times New Roman (Hebrew){\*\falt Thorndale};}{\f107\froman\fcharset178\fprq2 Times New Roman (Arabic){\*\falt Thorndale};}{\f108\froman\fcharset186\fprq2 Times New Roman Baltic{\*\falt Thorndale};}
{\f117\fmodern\fcharset238\fprq1 Courier New CE;}{\f118\fmodern\fcharset204\fprq1 Courier New Cyr;}{\f120\fmodern\fcharset161\fprq1 Courier New Greek;}{\f121\fmodern\fcharset162\fprq1 Courier New Tur;}
{\f122\fmodern\fcharset177\fprq1 Courier New (Hebrew);}{\f123\fmodern\fcharset178\fprq1 Courier New (Arabic);}{\f124\fmodern\fcharset186\fprq1 Courier New 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;}{\f343\fswiss\fcharset0\fprq2 @Arial Unicode MS Western;}
{\f341\fswiss\fcharset238\fprq2 @Arial Unicode MS CE;}{\f342\fswiss\fcharset204\fprq2 @Arial Unicode MS Cyr;}{\f344\fswiss\fcharset161\fprq2 @Arial Unicode MS Greek;}{\f345\fswiss\fcharset162\fprq2 @Arial Unicode MS Tur;}
{\f346\fswiss\fcharset177\fprq2 @Arial Unicode MS (Hebrew);}{\f347\fswiss\fcharset178\fprq2 @Arial Unicode MS (Arabic);}{\f348\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\mo10\dy7\hr10\min54}{\printim\yr2004\mo9\dy9\hr10\min40}{\version17}{\edmins10}{\nofpages4}{\nofwords1019}{\nofchars5812}{\*\company CNRS-HSU}{\nofcharsws7137}{\vern8269}}\margt2079 
\deftab1250\widowctrl\ftnbj\aenddoc\noxlattoyen\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\hyphcaps0\horzdoc\dghspace120\dgvspace120\dghorigin1701\dgvorigin1984\dghshow0\dgvshow3\jcompress\viewkind1\viewscale100\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 #6\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 Homework #6
\par }{\fs22 (no Week 7 Lab Exercise - Instructor on way to conference)
\par }{\b\fs22 
\par }\pard \s15\qc \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22 HW #6 due: Thursday, October 14th, 12:00 noon
\par }\pard \s15\ql \li0\ri0\nowidctlpar\aspalpha\faauto\rin0\lin0\itap0 {\b\fs22 ---------------------------------------------------------------------------------------------------------
\par }{\fs22 For EACH 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 yourL\hich\af0\dbch\af0\loch\f2 astName}{\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 }{\b\fs22 --------------------------------------------------------------------------------------------------------
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22\ul HOMEWORK #6
\par 
\par }{\b\fs22 0.\tab BEFORE }{\fs22 you proceed with this assignment, it is }{\b\fs22 IMPORTANT}{\fs22 
 that you have your cs-server pine program configured properly. This SHOULD have been taken care of earlier in the semester, but it is likely to be VITAL for this homework.
\par 
\par \tab So, double check:
\par }\pard \s15\ql \fi-420\li840\ri0\nowidctlpar\aspalpha\faauto\rin0\lin840\itap0 {\fs22 *\tab type pine from the cs-server prompt. You should be at pine's main menu.
\par 
\par *\tab type s to get to pine's setup screen.
\par 
\par *\tab type c to get to pine's setup configuration screen.
\par 
\par *\tab the 2nd and 3rd lines of the setup configuration screen should look like this:
\par 
\par }{\fs20\loch\af2 \hich\af0\dbch\af0\loch\f2 user-domain                   = humboldt.edu                               
\par \hich\af0\dbch\af0\loch\f2 smtp-server                   = axe.humboldt.edu
\par 
\par }\pard \s15\ql \fi-420\li1275\ri0\nowidctlpar\aspalpha\faauto\rin0\lin1275\itap0 {\fs22 *\tab if they are not, use the arrow keys to arrow down to each, and when you type Enter, you will be able to set them as needed.
\par 
\par }\pard \s15\ql \fi-420\li855\ri0\nowidctlpar\aspalpha\faauto\rin0\lin855\itap0 {\fs22 Once you have confirmed the above, you should be ready to proceed. }{\b\fs22 
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22 
\par 1.\tab }{\fs22 Consider: we've now discussed more about process management. In our examples, we tended to use traditional UNIX commands, but, once written, our Perl scripts are not that different!
\par 
\par \tab That is, you can use the system command to run a Perl script --- you could capture a Perl script's output using backquotes --- you could use a Perl process as a filehandle!
\par 
\par \tab For example, consider 480 HW #4's }{\b\fs22 fudd_converter}{\fs22 .  Why couldn't you call this script from within another Perl script? Why not, indeed?
\par 
\par \tab (You might wonder --- how can one script A call another script B such that script B gets called with script A's command line arguments? Well, it appears that calling script B with }{\b\fs22 @ARGV}{\fs22  from within script A does the trick...)
\par 
\par \tab Here's a TINY little warm-up script, first: write a script }{\b\fs22 fudd_test}{\fs22  that simply *calls* }{\b\fs22 fudd_converter}{\fs22 , passing }{\b\fs22 fudd_converter}{\fs22 
 fudd_test's command line arguments, if any. (This is not a particularly USEFUL script!! It is to convince you that this can work before the next two scripts.)
\par }{\b\fs22 
\par }{\fs22 \tab (If you didn't follow }{\b\fs22 fudd_converter}{\fs22 's specifications precisely with regard to command-line arguments and being cat-like, or if you just don't feel confident about it, you can find my non-elegant-but-fun
ctional example solution on the course Blackboard site, under "Selected Solutions".)}{\b\fs22 
\par 
\par 2.\tab }{\fs22 Here's another }{\b\fs22 TINY}{\fs22 \~little warm-up script. Write a script }{\b\fs22 fudd_backquotes}{\fs22  in which you call }{\b\fs22 fudd_converter }{\fs22 
within backquotes  --- again passing @ARGV as its argument, to give it the same command-line arguments that }{\b\fs22 fudd_backquotes}{\fs22  was called with --- in a LIST context. }{\b\fs22 
\par 
\par \tab }{\fs22 (This could be as the expression in a foreach; this could be assigning its results to an array. A call within backquotes that is }{\b\fs22 not}{\fs22  in a string context is acceptable.)
\par 
\par \tab To show that }{\b\fs22 fudd_backquotes}{\fs22  is doing something, print out each resulting line preceded with }{\b\fs22 fudd sez: }{\fs22 followed by a blank.
\par 
\par \tab That is, if input1 contained:
\par 
\par }{\b\fs22 \tab }{\b\fs20 That rascally RABBIT!}{\b\fs22 
\par }{\b\fs20 \tab He BOTHERS me!
\par }{\b\fs22 
\par \tab }{\fs22 then}{\b\fs22  fudd_backquotes input1 input1 }{\fs22 would cause this to be printed to the screen:
\par }{\b\fs22 
\par \tab }{\b\f2\fs20 fudd sez: Dat wascawwy WABBIT!}{\b\f2\fs22 
\par }{\b\f2\fs20 \tab fudd sez: He BODEWS me!
\par \tab fudd sez: Dat wascawwy WABBIT!
\par \tab fudd sez: He BODEWS me!
\par }{\b\fs22 
\par 3.\tab }{\fs22 Now, in }{\b\fs22 fudd_test}{\fs22  and }{\b\fs22 fudd_backquotes }{\fs22 you simply launched }{\b\fs22 fudd_converter}{\fs22 . Now, you are going to open it as a filehandle.}{\b\fs22 
\par 
\par \tab }{\fs22 Write a script}{\b\fs22  fudd_mailer}{\fs22 . It must meet the following specifications:
\par }\pard \s15\ql \fi-420\li840\ri0\nowidctlpar\aspalpha\faauto\rin0\lin840\itap0 {\fs22 *\tab for the files given on its command line (and behave in a cat-like way if there are no files given on the command line),
\par 
\par *\tab ...open up }{\b\fs22 fudd_converter}{\fs22  (with argument @ARGV) as an INPUT FILEHANDLE,
\par 
\par *\tab ...open up a mail process mailing to yourself ON AXE (remember the \\ before the @ !) as an OUTPUT FILEHANDLE,
\par 
\par *\tab read the results from the fudd filehandle into the mail filehandle.
\par 
\par *\tab (then, when you close the filehandles at the end, you should be sent a single e-mail message with those files' contents converted to fudd-speak...)
\par 
\par This is a little longer than the previous two, but not much!
\par }{\b\fs22 
\par }\pard \s15\ql \fi-420\li420\ri0\nowidctlpar\aspalpha\faauto\rin0\lin420\itap0 {\b\fs22 4.\tab }{\fs22 Finally, I think we need to practice with functions }{\b\fs22 index}{\fs22  and }{\b\fs22 substr}{\fs22 . We're going to write a weird script}{\b\fs22 
 limited_query_replace }{\fs22 to do this.}{\b\fs22 
\par 
\par \tab limited_query_replace }{\fs22 accepts names of files as command-line arguments, and behaves like }{\b\fs22 cat}{\fs22  if none are given.}{\b\fs22 
\par 
\par }{\tab It asks the user which string string-to-replace should have its FIRST instance in each line POSSIBLY replaced. (I said this was a weird script!) And, it should ask what string new-value it should be replaced with.}{\b 
\par }{
\par }{\b\fs22 \tab }{\fs22 Then it asks for the name that the user would like for the output file that result
s from this weird script. (As a little file-use reminder, then see if this output file exists --- if it does, warn the user that its current contents will be nuked, and proceed.)
\par 
\par \tab Use the }{\b\fs22 index}{\fs22  function to determine at what position the first instance of the string-to-replace appears in each line of the file(s) given as command-line arguments. If that string-to-replace\~
doesn't appear in that line, then simply write that line unchanged to the output file. 
\par 
\par \tab But, if }{\b\fs22 index}{\fs22  indicates that the string-to-replac
e DID appear in it, then your script then prints to the screen that current line, then a line containing a caret (^) underneath THAT position (at the position indicated by index, natch!). That is, the caret points to the beginning of the instance of strin
g-to-replace.
\par 
\par \tab [HINT: remember how you can repeat a string some number of times? It *can* work with a scalar variable... 8-) And remember how you can concatenate strings...]
\par 
\par \tab Then your script asks the user if this instance of string-to-replace should be replaced. If the user says y (for yes), replace it with the new-value; if the user says anything else, leave the line as it is. BUT --- you must somehow use }{\b\fs22 
substr}{\fs22  to accomplish this replacement, when the user requests it. And the resulting line should be written to the output file. 
\par }{\b\fs22 
\par }{\fs22 \tab [Another HINT: function }{\b\fs22 length}{\fs22  returns the length of a string ... why might that be useful with this use of }{\b\fs22 substr}{\fs22 , hmm...?]}{\b\fs22 
\par 
\par \tab }{\fs22 And it should, of course, close the output file when it is done! 8-)
\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 }{\b\fs22 480 hw 6 (NO ATTACHMENTS)}{\fs22 , and e-mail them to }{\b\fs22 
st10@humboldt.edu}{\fs22  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 
\par }}