Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

'use strict' without a semicolon can be interesting

by toma (Vicar)
on Jul 08, 2010 at 23:49 UTC ( #848783=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on 'use strict' without a semicolon can be interesting
Select or Download Code
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 ikegami (Pope) 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 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. ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://848783]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2014-07-23 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (146 votes), past polls