develooper Front page | perl.perl5.porters | Postings from February 2022

Re: The explicit strict hints bits - Can we remove them?

Thread Previous | Thread Next
Paul "LeoNerd" Evans
February 4, 2022 00:22
Re: The explicit strict hints bits - Can we remove them?
Message ID:
On Fri, 4 Feb 2022 07:36:21 +0800
Tom Molesworth via perl5-porters <> wrote:

> The concept seems reasonable, just not too clear on exactly what's
> being suggested - would this affect these two cases, for example?
> { # Only using some of the features, e.g. variables should be
> declared, but keep barewords and symbolic references enabled
>  use strict 'vars';
>  our $x = example; # should be fine
>  $y = 'compile-time error'; # should fail
> }
> and
> use strict;
> { # limited-scope disabling of a feature
>  no strict 'refs';
>  our $typo;
>  my $name = 'whatever';
>  *$name = sub { # this part is fine
>   ++$tpyo # would want a compile-time error here
>  };
> }

Those two examples would be exactly as they are, entirely unaffected.

My suggestion only relates to the *implict* enabling of strictness
flags by the `use VERSION` syntax. Or rather, the way that strictness
flags are turned off - or not - by a later `use VERSION` declaration
giving a version number under 5.12, after you have explicitly turned
them on by a `use strict` statement.

For example,

  use v5.14;
  use strict;

  our $typo;

  use v5.0;
  ++$tpyo; # the strictness flags would now be turned off.

In practice it is *extremely* rare to see subsequent `use VERSION`
declarations after the first one at the top of a file, and then even
rarer to see them specify a smaller version number than 5.12. I think
it extremely unlikely there is any real code around that would be
affected by the proposed change.

The only situations that would be affected require both:

  * An explicit `use strict` or `use strict SOMEFLAGS`

  * A `use VERSION` of a version number smaller than v5.12 on a line
    later on

If you never `use v5` or `use v5.0` or whatever (of a number smaller
than v5.12), or the only `use v5` line is the first line in the file (or
at least, above any `use strict`) then no difference to current
behaviour is expected.

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About