[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: [ID 20000111.008] use strict 'vars'



>use strict 'vars' seems to ignore the variables '$a' and '$b'. It works
>fine for '$c', '$d' ...

>#/usr/bin/perl
>use strict 'vars';

>$a = 2;

># this code should not work but does.

    % man strict
    ....
    `strict vars'
          This generates a compile-time error if you access a variable
          that wasn't declared via `use vars', localized via `my()'
          or wasn't fully qualified. Because this is to avoid variable
          suicide problems and subtle dynamic scoping issues, a merely
          local() variable isn't good enough. See the my entry in the
          perlfunc manpage and the local entry in the perlfunc manpage.

              use strict 'vars';
              $X::foo = 1;         # ok, fully qualified
              my $foo = 10;        # ok, my() var
              local $foo = 9;      # blows up

              package Cinna;
              use vars qw/ $bar /;        # Declares $bar in current package
              $bar = 'HgS';               # ok, global declared via pragma

          The local() generated a compile-time error because you just
          touched a global name without fully qualifying it.

---->     Because of their special use by sort(), the variables $a and
---->     $b are exempted from this check.

Perhaps they should be listen in perlvar as well.  I notice @F is 
also missing from perlvar.  What else are we forgetting?

I further note that `man strict' doesn't mention Larry's spiffy new
our() operator.  Oughtn't it?

--tom


Follow-Ups from:
Larry Wall <larry@wall.org>
References to:
Christian Cadieux <ccadieux@ccadieux.Central.Sun.COM>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]