Gavilan

CSIS054: Perl Programming

Homework set 1

 

What to turn in:

You will upload a single plain-text file containing your answers to the entire assignment. Since some of your answers should be contained in a single file, (for example, #4, below, is a self-contained script) I ask that you indicate the questions you are answering like this:

 

### Q1 ###

Answer to question 1 here. Depending on the question, your answer will be in English or in perl code. If its in perl code, you can paste it directly from your script. Naturally, there will be plenty of comments in your code.

Comments are there to explain what your code is doing (if it isn't obvious) or why your code is doing it that way (if it isn't obvious). Comments are not strictly necessary, just like in the real world. It is better to have no comment, than to have a misleading or incorrect comment.

All scripts should have a comment in the first few lines that tells the name of the script and a brief summary of what it does.

If your answer is in English, it is in complete sentences, with punctuation, capitalization, and proper grammar. This matters. It does not have to be excessively formal. It does have to be clear, concise, and readable.


### Q2 ###

Again, note the format between answers. Three hash marks, space, capital Q, number, space, 3 hash marks, and a newline. As you become more familiar with perl and its conventions, you will see why we like to be so particular.


### Q3 ###

#!/usr/bin/perl

# sample.pl - this script demonstrates a complete answer to a homework problem

print "If this were the actual answer, there would be some math here.\n";


### Q4 ###

#!/usr/bin/perl

# nag.pl - this script tells the user what is in a good script.

# First I make some arrays
@goodstuff_has = ("clear comments", "organized code", "consistent whitespace and indentation", "URLs in the comments if something external is used");

@goodstuff_is = ("maintainable", "a pleasure to read", "as simple as possible, but no simpler");

# Then make sentences out of them
foreach $s (@goodstuff_has) { print "A good script has $s.\n\n"; }

foreach $s (@goodstuff_is) { print "A good script is $s.\n\n"; }

 

1. Enter the hello.pl/hello2.pl scripts and run them on your computer. Did it work as expected?

Which perl interpreter are you using? Which text editor are you using?

 

2. Type perldoc chomp at the command line, OR, look up the chomp function on the perlfunc reference page. What does the chomp function do?

 

3. Write a script that computes 4.444 x 5.555.

 

4. Modify the madlib.pl script to display a story that you invent. Change the nouns, verbs, and other word types as needed to make your story interesting.

 

 

 

 



Address of this page is http://hhh.gavilan.edu/phowell/csis054/01problems1.html
Please contact Peter Howell at phowell@gavilan.edu for questions or comments.
Last updated January 10, 2010.