Jonathan's Corner
(Search & Sitemap)
> A Library of Free Online Books to Read >
Miscellaneous Nonfiction >
Tinkering with Perl
Skip Back
Previous
25
26
27
28
29
30
31
32
33
34
Next
Skip Forward
Printer-Friendly Version
There are a few ways to assign a list. One way is like this:
@MyFriends = ("John", "Susan", "Mary");
The list is assigned to something described by a left parenthesis ('('), some scalars separated by commas (','), a right parenthesis (')'), and then the semicolon (';'). You can use variables and numbers as well as just strings, like this:
@Numbers = ($LastNumber, 9);
You can also put everything that's in one list, into another list. For example, you might write:
@PeopleIKnow = (@MyFamily, @MyFriends, "Jane", "Bob");
Then the list of people you know includes everybody in the lists of your family and friends, plus Jane and Bob.
One thing you will do often is to add one element to a list. Suppose you have a new friend named Fred, and you want to add him to your list of friends. You could do it this way:
@MyFriends = (@MyFriends, "Fred");
Now, I would like to answer a question you may have == how can MyFriends be equal to itself plus "Fred" added on to the end? That is like saying that a number equals itself plus one.
The answer is that the statement should be read like this: "Let the new value of MyFriends equal the old value of MyFriends, with "Fred" added at the end. It is possible, and useful at times, to use one variable on both sides of the equals sign ('=') in this way.
Variables in general - Lists - Statements - Assignment of variables in general - Assignment of scalars - Assignment of hashes - 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.)
Jonathan's Corner
(Search & Sitemap)
> A Library of Free Online Books to Read >
Miscellaneous Nonfiction >
Tinkering with Perl
Skip Back
Previous
25
26
27
28
29
30
31
32
33
34
Next
Skip Forward
Printer-Friendly Version