Skip to Content
Perl Debugged
book

Perl Debugged

by Peter Scott, Ed Wright
March 2001
Intermediate to advanced
288 pages
4h 56m
English
Addison-Wesley Professional
Content preview from Perl Debugged

8.2. A Menagerie of Typos

At this point, we're going to go on a tour of typo examples with different diagnoses.

8.2.1. Quotable Quotes

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe
Pro Perl

Pro Perl

Peter Wainwright
Intermediate Perl

Intermediate Perl

Randal L. Schwartz, brian d foy, Tom Phoenix
Perl Testing: A Developer's Notebook

Perl Testing: A Developer's Notebook

Ian Langworth, Chromatic

Publisher Resources

ISBN: 0201700549Purchase book