Re: strict behavior with .pm
- From: mritty@xxxxxxxxx (Paul Lalli)
- Date: Sat, 29 Sep 2007 04:53:37 -0700
On Sep 28, 5:18 pm, perl...@xxxxxxxxxxxxxxxx (Jeremy Kister) wrote:
Given the below code, is there something that will warn/prevent me from
declaring $variable when i really meant @variable ?
I usually use perl -wTc scriptname to check for silliness, but i've
realized code in the below fashion won't be reported. This got me very
confused under mod_perl, because @variable contained things seemingly
unrelated to what i expected.
__BEGIN__
#!/usr/local/bin/perl
use strict;
use My::Example;
my $example = My::Example->new();
my $ref = $example->go();
__END__
Presumably, this __END__ and __BEGIN__ notation means that these are
two different files?
If so, you're only using strict in the first file. strict is a
lexically scoped pragma. It only affects the file in which it is
placed. (It actually only affects the block in which it's placed, but
you didn't place it in any block, so the scope is the file itself)
__BEGIN__
package My::Example;
Put:
use strict;
here again, and strictures will be enabled in My/Example.pm as well.
sub new {
return bless({}, shift);}
sub go {
my $variable;
push @variable, 1;
return(\@int);}
1;
__END__
Paul Lalli
.
- References:
- strict behavior with .pm
- From: Jeremy Kister
- strict behavior with .pm
- Prev by Date: Re: Bundle::CPAN install error
- Next by Date: Re: $File::Find and no_chdir
- Previous by thread: Re: strict behavior with .pm
- Index(es):