On Sep 28, 5:18 pm, [EMAIL PROTECTED] (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([EMAIL PROTECTED]);}
>
> 1;
> __END__


Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to