Q&A

Q1: I want to iterate over a string and count the occurrences of the letter t. How can I do this in Perl?
A1: Well, you could use a for loop and one of the string functions to work your way through the string one character at a time, but that would be a terrible amount of overkill (and expose you as a C programmer who still thinks of strings as null- terminated arrays). Perl's good with strings, and it has built-in mechanisms for finding stuff in strings so you don't have to do perverse character-by-character comparisons. You'll learn more about this sort of pattern matching on. Don't spend a lot of time iterating over strings until you read that.
Q2:I don't understand why in these scripts you are testing for nonnumeric data using \D, when ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.