March 2001
Intermediate to advanced
288 pages
4h 56m
English
At this point, we're going to go on a tour of typo examples with different diagnoses.
Our first program sets up a hash %quotation indexed by author and then goes on:
while (my ($author, $quote) = each %quotation)
{
print 'Quote of the Day: "$quote" by $author\n';
}
This runs, but takes us too literally:
Quote of the Day: "$quote" by $author\nQuote of the Day: "$quote" by $author\nQuote of the Day: "$quote" by $author\n...
Aha! Nothing is being interpolated because we're using single quotes. We change them to double quotes:
3 while (my ($author, $quote) = each %quotation)
4 {
5 print "Quote of the Day: "$quote" by $author\n";
6 }
Yikes, now we get three errors:
Scalar found where operator ...