in reply to Beginner question - understanind a loop with a file handle
If your files contains numbers (as in, sequences of digits, 0-9), then the numbers will be treated by Perl as numbers:
1 2 3 4 5
Then, the variable names will make sense, $total will contain the sum of all numbers, while $count will contain the number of lines in the file.
What you (or the book) might be missing is an explanation that Perl does not really discriminate between strings and numbers and will transparently convert from one to the other. Only strings that don't look like a number will get converted to 0.
|
|---|