in reply to require $package?

I've got a new problem now... but in the same area.

sub loadmod(@){ shift if(ref($_[0])); $@ = 0; foreach (@_){ croak("loadmod() cannot load any packages outside of it's own pa +ckage area (RPG). Package Requested: $_") unless($_ =~ m/^RPG::/o); eval "require $_; "; croak("Unable to locate $_ \@INC includes: ".join(", ", @INC)) i +f($@); } }

If I comment out the second croak line, nothing important happens, however if I leave it like this, I get this error:
syntax error at E:/Perl/lib/Carp/Heavy.pm line 1, near "package Carp"
Compilation failed in require at E:/Perl/lib/Carp.pm line 109.

Called with: loadmod qw(RPG::Item::Weapon::Spear);

I'm lost with that error..


"Wierd things happen, get used to it"

Flame ~ Lead Programmer: GMS
http://gms.uoe.org

Replies are listed 'Best First'.
Re (tilly) 1: New Problem?
by tilly (Archbishop) on Oct 17, 2001 at 06:31 UTC
    It looks like you are running a messed up Perl 5.6 installation. Try the following code:
    use Carp; croak("Test croak");
    My bet is that you will get the same error. And the problem is that E:/Perl/lib/Carp/Heavy.pm probably has a syntax error in it. (Did someone edit it?) When you load Carp you don't see this error because the bulk of the module is autoloaded upon use. (This started with Perl 5.6, which is why I knew what version of Perl you had.)

    But even if you fix that, you should work on your error handling. Using eval will trap errors, but if you are using eval, you should include $@ in your error message instead of guessing at what is wrong. Alternately you can use the file naming version of require. But as your code stands if your module doesn't return a true value, you will get an error that is confusing and counterproductive because it is wrong. (require is failing on a false return, but you will think it can't be found.)

      First: I've been able to use Croak in other sections of the module...

      Hmm, this is interesting though... I just looked through the code for the Spear package... I'm missing a semicolon on the first line ("package RPG::Item::Weapon::Spear")... heh...
      Well... after adding that, everything seems fine... Thanks for the help. :)


      "Wierd things happen, get used to it"

      Flame ~ Lead Programmer: GMS
      http://gms.uoe.org
        This is rather frustrating. I put a lot of energy into becoming a competent Perl programmer, I tell you a lot of valuable information point blank, and you just ignore it all?

        Sure, you have lots of croak calls. But if your code is like any half-way sane person's, none of them are expected to be called in regular use. Now based on what happened when you did call it, I am willing to bet that your installation is messed up.

        I am telling you that based on quite a bit of experience. Please do not disregard that statement. If it is true, then all of your error handling is going to be giving you back useless error messages. If you are a good programmer, that statement should bother you. A lot.

        Furthermore compare the error with what your code tries to put out. Your error reporting doesn't actually give the error it is supposed to. That is worrisome. However even if your code worked as you expect, the error message that you would have gotten would be wrong and misleading. That underscores my point that I made before about error handling, which you seem to be ignoring. But a good programmer wouldn't ignore that. A good programmer should be bothered if error handling gives you messages that send you down a blind alley. A good programmer doesn't want to make debugging harder.

        So I am telling you the following.

        1. I think you are dismissing my belief that your installation has problems far too easily.
        2. The fact that there is no connection between what the error was and what the message is that you got should be a giant red flag that should worry you.
        3. Your error handling is broken and needs fixing. Even if you got the message that you had worked to put there, the result would have just left you confused again. If you take the suggestions that I gave you earlier, this would not happen again.
        4. Your motto is, typos and all, "Wierd things happen, get used to it". Well that attitude is extremely dangerous in a programer. Yes, weird stuff happens. But you shouldn't just learn to live with it. Instead you should be bothered by it, investigate it, and make it so it doesn't happen any more.
        Well if I wasn't sick as a dog, I probably would rewrite this to come off in a kinder way. But I am, and I think that what I am saying has value. So please ignore the tone if you need to and focus on the message...