(Search & Sitemap)
> Writing >
Miscellaneous Nonfiction >
Tinkering with Perl
Skip Back
Previous
51
52
53
54
55
56
57
58
59
60
Next
Skip Forward
Printer-Friendly Version
What happens if you run the following code:
$a = 1;
$b = 2;
if ($a = $b)
{
print "They're equal!";
}
else
{
print "They're not equal.";
}
What would you like to happen? It compares 1 and 2 and says that they're not equal. However, if you run this, it says that they're equal. Why? ($a = $b) says to make a equal to b. What we wanted was ($a == $b), which would compare them.
Use '=' to assign a value and '==' to compare. It's easy to use the wrong one and introduce bugs to your program.
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
51
52
53
54
55
56
57
58
59
60
Next
Skip Forward
Printer-Friendly Version