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

Ok, here is the situation: I have a file x.pm consisting of this two lines
use strict; use base Exporter;
When I "use x;" or "perl -Mx" I get an "Unknown error", "perl x.pm" says whats wrong. Why the difference? And why doesnt stand Exporter for itself anymore?

Replies are listed 'Best First'.
Re: Unknown error
by jdporter (Paladin) on Mar 01, 2006 at 16:04 UTC

    The problem is that the arguments of use base are supposed to be strings. Change your code to this:

    use strict; use base 'Exporter'; 1;

    You'll also need to have that final 'true' value, or there will be an error loading your module. (Try it and see.)

    We're building the house of the future together.
      Yes I know (now). "perl x.pm" explained it to me. As I said in the OP. My question is about the diff in use vs main. And in older perl a word (especially a package name) would be seen as a string const of itself when no function of this name was declared. Why not here? In e.g. new it is so.
        What difference? Copy and paste
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Unknown error
by ikegami (Patriarch) on Mar 01, 2006 at 18:56 UTC

    I narrowed the bug: Compile time strict sub violations in required modules result in Unknown error.

    • Other strict violations output the correct error message.
    • Run-time strict sub violations output the correct error message.
    • strict sub violations in the main file output the correct error message.

Re: Unknown error
by ikegami (Patriarch) on Mar 01, 2006 at 18:26 UTC

    Update: Oops! Misread OP. Ignore this post.

    I get the same error message both ways:

    >perl -v This is perl, v5.6.1 built for MSWin32-x86-multi-thread ... >perl -Mx -e "" Unknown error Compilation failed in require. BEGIN failed--compilation aborted. >perl -e "use x;" Unknown error Compilation failed in require at -e line 1. BEGIN failed--compilation aborted at -e line 1. >perl script.pl Unknown error Compilation failed in require at script.pl line 1. BEGIN failed--compilation aborted at script.pl line 1.

    and

    >perl -v This is perl, v5.8.0 built for MSWin32-x86-multi-thread ... >perl -Mx -e "" Unknown error Compilation failed in require. BEGIN failed--compilation aborted. >perl -e "use x;" Unknown error Compilation failed in require at -e line 1. BEGIN failed--compilation aborted at -e line 1. >perl script.pl Unknown error Compilation failed in require at script.pl line 1. BEGIN failed--compilation aborted at script.pl line 1.
      not "perl script.pl" where script.pl probably contains "use x", "perl x.pm" instead. In "::main" instead of "use".