http://www.perlmonks.org?node_id=848783

toma has asked for the wisdom of the Perl Monks concerning the following question:

Someone ran across a problem in some production code where there was a missing semicolon after use strict. The problem reduces to this:

perl -e 'sub {use strict my @s = @_;}'

It seems to me like it would be nice if this gave some sort of an error. Am I missing something? The problem was found with perl 5.8.4 and still behaves the same way in perl 5.8.12 (edit: oops, I meant 5.12.1)

It should work perfectly the first time! - toma

Replies are listed 'Best First'.
Re: 'use strict' without a semicolon can be interesting
by ikegami (Patriarch) on Jul 09, 2010 at 00:08 UTC

    It seems to me like it would be nice if this gave some sort of an error.

    The syntax for use is use Module EXPR;, where EXPR is an expression that returns a list of symbols to import (or a list of strictures to enable in strict's case), and that's exactly what you provided. How can Perl possible know that what you meant something other than what you told it?

    still behaves the same way in perl 5.8.12.

    5.8.9 is the highest release of 5.8. You probably meant 5.12.0 or 5.12.1.

      Perhaps there are a limited number of strictures that use strict knows about. Perl could compare the EXPR list against the known list of possible strictures, and throw an error or warning if the EXPR is not on the list.

      I don't know if this is feasible to implement without deep changes, but it does seem possible.

      You are right, I meant perl 5.12.1!

      It should work perfectly the first time! - toma

        It already does that.

        $ perl -e'use strict "foo"' Unknown 'strict' tag(s) 'foo' at -e line 1 BEGIN failed--compilation aborted at -e line 1.

        You passed an empty list which is perfectly valid (i.e. the same as use strict;).

Re: 'use strict' without a semicolon can be interesting
by Anonymous Monk on Jul 08, 2010 at 23:59 UTC
    Thats weeeeeird :D
    $ perl -MO=Deparse -e "sub {use CGI my @s = @_;} " use CGI (my(@s) = @_); sub { } ; -e syntax OK $ perl -MO=Deparse -e "sub {use strict my @s = @_;} " sub { } ; -e syntax OK
Re: 'use strict' without a semicolon can be interesting
by JavaFan (Canon) on Jul 12, 2010 at 10:27 UTC
    It seems to me like it would be nice if this gave some sort of an error.
    I think anyone would appreciate it if Perl magically can detect when a programmer writes something he didn't intend, while never triggering when the programmer writes what he intends.

    Unfortunally, noone has ever been so smart as to write the code for this.

    Am I missing something?
    Programmers are still responsible for what they write. ;-)