I was happily hacking away when suddenly one of my modules stopped working with the error 'Can't locate object method "Package" via package "my_module" at my_module.pm line 1.' As an added bonus, mod_perl vomited the calling program into the logs - twice.

Veterans are already smirking because they know what the problem is. Twenty minutes afterwards, I did too. Turns out that the line

package my_module;

had been changed to

Package my_module;

by vi. It turns out that in the version I have, if I am in vi mode mode and press page down, it capitilises the letter under the cursor and then switches to ex mode so that the next page down starts moving me down pages. I'm so disgusted I'm tempted to go and learn Emacs right now, but I'll leave it 'till the morning in case I change my mind :)

Of course I didn't notice the capital letter on 'Package' in the error message because I had never had the error 'Cannot locate object method "package"... ' either.

And people wonder why computer programmers are all pedants...

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

Replies are listed 'Best First'.
Re: VI VI VI - the number of the beast
by Masem (Monsignor) on May 05, 2001 at 19:03 UTC
    *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
      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
      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!

Re: VI VI VI - the number of the beast
by yakko (Friar) on May 06, 2001 at 09:20 UTC
    As for the mechanics of -why- this happened... the ~ command toggles capitalisation. Now, when you hit PgDn within a vi that doesn't handle it (such as on any Sun), you'll send something like ^[[4~, where the ^[ is the escape character. This turns off insert mode, puts you into command mode, beeps on the [4, and sends the tilde key, toggling caps for the letter under the cursor.

    vim of course handles these keys properly in insert mode!

    (Update: corrected [4 sequence)

    --
    Me spell chucker work grate. Knead grandma chicken.

Re: VI VI VI - the number of the beast
by lemming (Priest) on May 05, 2001 at 22:12 UTC
    Hmmm. Which vi are you using and on what system?
    No problems like that with vim 5.7 on either windows or Linux.
    And for the Perl bit, I always do a quick check with perl -cw to catch syntax errors.
      Dunno. It came with Debian 2.2 r0 . It's probably vim or elvis anyway. I just tend to lump them all together as vi since they all act (roughly) the same anyway. The other annoying thing I have noticed is that moving the cursor to the very left of the screen with the cursor keys takes it out of insert mode - very annoying when trying to comment out lines. I haven't noticed it in any other version.

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

Re: VI VI VI - the number of the beast
by virtualsue (Vicar) on May 07, 2001 at 14:08 UTC
    I suppose this trial was sent to you as a reminder to use vi in the sanctified manner. Keys such as Page Down are system-specific and therefore sinful & unholy.   ;-)
Re: VI VI VI - the number of the beast
by alfie (Pilgrim) on May 07, 2001 at 16:04 UTC
    Well, maybe you should learn how to :map your <PageDown> key to the thing your terminal is sending? I sometimes stumbled upon that, too - but that can easily be resolved by LARTing the sysadmin that is responsible for that broken termcap entry. Don't blame vi.

    For you said it was a Debian box - the default vi is nvi on that machines. And don't blame vi your ignorance (sorry to call it that way - but it simply is nothing else) for the standard vi behavior that causes you to get out of insert mode when hitting a cursor key. apt-get install vim and :set esckeys. :help esckeys to see what it does.
    --
    use signature; signature(" So long\nAlfie");