in reply to VI VI VI - the number of the beast

*cough*-w*cough*use strict*cough*cough*

(I know you found your error, but the fact that you say it's on line 1 implies that neither mechanism is set, and I betcha that perl would have seen that immediately).


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: VI VI VI - the number of the beast
by DrZaius (Monk) on May 05, 2001 at 20:02 UTC
    hmmm
    Package my_package; use strict; use constant USES => 'goes after package';
    :)
      Well, the use strict has to be inside the package statement for the package to be using strict, but since you can define multiple packages within a single file, it's still a good idea to toss an extra use strict at line 2 or 3 (assuming that line 1 is "#!/usr/bin/perl -wT").
      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
        Packages don't actually use strict. strict simply takes effect until the end of the lexical scope in which it occurs (either file or block). Package declarations don't matter to the strict pragma.

        Here's an example:

        #!perl use strict; package First; $x = 1; package Second; $y = 2; __END__ Global symbol "$x" requires explicit package name at - line 7. Global symbol "$y" requires explicit package name at - line 11. Execution of - aborted due to compilation errors.
Re: Re: VI VI VI - the number of the beast
by jepri (Parson) on May 05, 2001 at 19:49 UTC
    Bam!

    Holsters gun. ;)

    orange:/usr/lib/cgi-bin/perl# perl -w event_dates.pl Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Can't locate object method "Package" via package "Common_event +" at Common_event.pm line 1. require Common_event.pm called at event_dates.pl line 16 main::BEGIN() called at Common_event.pm line 0 eval {...} called at Common_event.pm line 0 main::BEGIN() called at Common_event.pm line 16 eval {...} called at Common_event.pm line 16 BEGIN failed--compilation aborted at event_dates.pl line 16.

    Update: this line is totally and utterly wrong. I only leave it in so that chipmunks reply below makes sense.

    And strict should have been inherited from the calling script.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

      And strict should have been inherited from the calling script.
      I don't know if you meant that seriously... Apologies if this post is unnecessary.

      strict is a lexical pragma, which means that affects only the rest of the enclosing scope, either block or file. So, use strict in the main script will not affect loaded modules, and vice versa.

      Imagine if it didn't work that way... after putting use strict in your script, you wouldn't be able to use any modules which weren't strict-safe!

        No apologies needed, you caught me in a brain-slip moment.

        As it happens, the second line was use strict, and when I interchanged them:

        orange:/usr/lib/cgi-bin/perl# perl -w event_dates.pl Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Can't locate object method "Package" via package "Common_event +" at Common_event.pm line 2. require Common_event.pm called at event_dates.pl line 16 main::BEGIN() called at Common_event.pm line 0 eval {...} called at Common_event.pm line 0 main::BEGIN() called at Common_event.pm line 16 eval {...} called at Common_event.pm line 16 BEGIN failed--compilation aborted at event_dates.pl line 16.

        I don't think that there was anything I could have reasonably done to get more protection from a problem like that.

        ____________________
        Jeremy
        I didn't believe in evil until I dated it.