Another statement: our

Within a package, if you want to use a global (package) variable without prefixing the package name, use the our statement. The our statement allows the package variable name to be used within the module without being fully qualified (as shown in Listing 17.5), and visible outside of the package if it's fully qualified.

Listing 17.5. The our Statement
1:  #!/usr/bin/perl –w
2:
3:  use strict;
4:  our $max = 15;
5:
6:  sub read_max {
7:      my $counter = 0;
8:
9:      while(<DATA>) {
10:         my $line = $_;
11:         if ($counter++ < $our) {
12:             print $line
13:         }
14:     }
15: }
16: read_max();
					

Forcing Your Names on Others

There is one small difference between the File::Find module from Hour 14 and the statistics module from Listing 17.1 (beyond ...

Get SAMS Teach Yourself Perl in 24 Hours THIRD 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.