(Search & Sitemap)
> Writing >
Miscellaneous Nonfiction >
Tinkering with Perl
Skip Back
Previous
33
34
35
36
37
38
39
40
41
42
Next
Skip Forward
Printer-Friendly Version
Remember, back when we introduced statements, how we talked about going to a friend's house? Let me reproduce the list of what to do:
Ask your parents for permission to visit your friend.
Call your friend's house, and ask permission to come over.
Finish getting dressed.
Walk over to your friend's house.
Take chewing gum off of your shoe.
Greet your friend.
Play with your friend.
Eat a snack.
Play some more.
Say goodbye.
Walk home.
Take off your shoes.
Well, this list didn't involve any decisions -- and there are decisions involved. For example, you only continue over to your friend's house if you get permission, right?
Let's rewrite the list using if-then logic:
Ask your parents for permission to visit your friend.
If your parents give permission to visit your friend:
{
Call your friend's house, and ask permission to come over.
If your friend's parents give permission to come over:
{
Finish getting dressed.
Walk over to your friend's house.
If you stepped on some chewing gum:
{
Take chewing gum off of your shoe.
}
Greet your friend.
Play with your friend.
Eat a snack.
Play some more.
Say goodbye.
Walk home.
Take off your shoes.
}
}
What we have here is a modified list of how to visit your friend, that only does things if they are appropriate -- for example, it only goes over to your friend's house if you have permission to go over.
The syntax in Perl (how you tell the computer to do something) is as follows for this sort of thing:
if (condition)
{
code to execute if condition is true
}
"if" must be spelled exactly that way, with a lowercase 'i', and the curly braces put around the code to be executed. What Perl will do when it sees that, is see if the conditional clause is true, and if so, execute the block that's inside the braces.
Statements - Flow control - Blocks - Conditional clauses - If-then-else - If-then-else chains
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
33
34
35
36
37
38
39
40
41
42
Next
Skip Forward
Printer-Friendly Version