June 2005
Beginner
480 pages
10h 31m
English
In Hour 5, “Working with Files,” you learned about variables and variable scope. Specifically you learned that the my keyword declares that a variable is local only to the program, or to any curly braces that might be around it. Look at the example in Listing 17.3.
1: #!/usr/bin/perl –w
2:
3: use strict;
4: my $max = 15;
5:
6: sub read_max {
7: my $counter = 0;
8:
9: while(<DATA>) {
10: my $line = $_;
11: if ($counter++ < $max) {
12: print $line
13: }
14: }
15: }
16: read_max();
|
The variable $max is visible anywhere within the program, $counter is visible only within the subroutine, and $line is visible only within the while loop.
In Hour 5, I said that with strict in place you had to declare ...
Read now
Unlock full access