(Search & Sitemap)
> Writing >
Miscellaneous Nonfiction >
Tinkering with Perl
Skip Back
Previous
16
17
18
19
20
21
22
23
24
25
Next
Skip Forward
Printer-Friendly Version
When you are writing a program, you are writing for people as well as computers. Most of the time, after a program is written, you or someone else will want to make changes -- to add new features, or to fix bugs. There is a joke which my father likes to tell:
A construction worker, at lunch break, opens his lunchbox, and says, "Salami again! I hate bologna!"
Then, the next day, he says, "I wonder what I have today." He opens his lunchbox, and says, "Bologna again? I hate bologna!"
This continues for a week. Finally, one of his coworkers says, "Why don't you ask your wife to give you something else for lunch? That way, you wouldn't have to have bologna all the time."
The construction worker says, "Oh, I don't have a wife. I make my own lunches!"
In this joke, the construction worker eats the sandwiches he hates because that's what he made earlier. This joke is a lot like programming. The construction worker is like a programmer, and the yucky bologna sandwiches are programs that don't have very many little notes, in English, to explain things. It can be very difficult, even for experienced programmers, to figure out or remember what a program is doing if it doesn't have notes to explain things. These little notes are called comments, and you can say anything you like in a comment. (But we generally use comments to explain programs.)
Comments are done differently in different computer languages, but there is some feature that tells the computer what is a comment and what is the rest of the program. In perl, a comment begins with a hash mark ('#'), and continues to the end of the line. If you want to make a comment that uses more than one line, put a hash mark on a second line. Here are some examples of what is and is not a comment:
# This is a comment.
# This is a comment, which
# uses more than one line.
#
# This is a comment, too. It uses blank lines to make
# things better to look at.
#
# This is a comment which begins in the
# middle of a line. You can put a
# comment to the right of something
# else, to explain what it does.
This is not a comment.
The comment begins #here.
Tinkering with Perl is a free book that provides an introduction to programming in Perl, as well as a basic reference for things like foreach in Perl, if-then, and if-then-else, in addition to providing a glossary where you can find definitions for concatenate and other terms.
Tinkering with Perl may be one of the most popular offerings on this site, but it's not the only attraction. You can read a tongue-in-cheek Game Review: Meatspace, read an even more offbeat customer service survey (whether or not you actually fill it out), and spend a few minutes wishing your boss would read, The Administrator Who Cried, "Important!" (Not to mention that there are other things you can read here besides tech stuff, from Janra Ball: The Headache to The Spectacles.)
(Search & Sitemap)
> Writing >
Miscellaneous Nonfiction >
Tinkering with Perl
Skip Back
Previous
16
17
18
19
20
21
22
23
24
25
Next
Skip Forward
Printer-Friendly Version