Tinkering with Perl

Jonathan's Corner (Search & Sitemap) > Writing > Miscellaneous Nonfiction > Tinkering with Perl
Skip Back  Previous  39  40  41  42  43  44  45  46  47  48  Next  Skip Forward
Printer-Friendly Version

Subroutines and functions

When you learned to walk, it was a bit tough to learn -- but once you had learned once, you learned a way of walking that would take you anywhere (within certain bounds), on any kind of surface (within other bounds). You had learned walking in general, and so you didn't need to learn to walk each time you met something new.

For computers, there are many things you'll want to do a number of different times, in a number of different places -- but it's really only one thing. With subroutines and functions, you can write miniature programs that do one thing -- and then you have a new command that is available to you, taking only one line, whenever you want to do something.

Subroutines are powerful. Subroutines are good. Whenever you find yourself doing the same thing in more than one place, it is probably good to put it in its own subroutine.

See also:

Variables - Statements - FLow control - Blocks - Arguments - Subroutines - Functions

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.)

Read more...

Top

Jonathan's Corner (Search & Sitemap) > Writing > Miscellaneous Nonfiction > Tinkering with Perl
Skip Back  Previous  39  40  41  42  43  44  45  46  47  48  Next  Skip Forward
Printer-Friendly Version