S
sln
Lexical variables were introduced in Perl 5.
In Perl 4 and before, package variables where all there was.
You are correct!
However the primary benefit of using lexical variables is for the programmer,
rather than for the interpreter.
Here is another mantra that will serve you well:
Always prefer lexical variables (my) over package variables (our),
except when you can't.
Yes you can.
-------------------
#!/usr/bin/perl
use warnings;
use strict;
$main::var = 'some value';
print "$main::var\n";
-------------------
Works fine...
Then you don't *want* them to be package variables.
Since you _can_ use lexical variables, then following the mantra,
that is what you should use.
You are not looking in the right place then.
I dashed off this crude test:
-------------------
#!/usr/bin/perl
use warnings;
use strict;
use File::Find;
my @files;
find( \&is_module, @INC );
my $module_cnt = @files;
print "$module_cnt module files found\n";
my $strict_cnt;
foreach my $file ( @files ) {
$strict_cnt++ if qx/grep -l 'use strict;' $file/;
}
print "$strict_cnt module files found that use strict\n";
my $percent = sprintf '%.0f', ($strict_cnt / $module_cnt) * 100;
print "$percent% of modules have strict enabled\n";
sub is_module {
push @files, $File::Find::name if /\.pm$/;
}
-------------------
About 80% of the modules on my system appear to have strict enabled.
Please post Real Perl Code rather than attempt to paraphrase Perl code.
Case matters.
Putting the "use strict" (not "use Strict", case matters) "down here"
will not change anything. You'll get the same error regardless of
where in the file the "use strict" statement is.
To use your package variable with strict enabled you must either declare it:
our $IwannaBeApackageGlobal = "do use strict";
or use the explicit package name:
$FunStuff::IwannaBeApackageGlobal = "do use strict";
Thans Tad!
sln