Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re7: Error module

by hotshot (Prior)
on Aug 19, 2003 at 15:37 UTC ( [id://284938]=note: print w/replies, xml ) Need Help??


in reply to Re7: Error module
in thread Error module

First of all, thanks for your patience. Secondly, I still can't seem to get this going, I acted exactly as you said, created /usr/local/bin/MyErrors/SomeError.pm with the contents:
package MyErrors::SomeError; use Error::Simple; @ISA = qw(Error::Simple); 1;
Then I'v created /usr/local/bin/test.pl with the following contents:
#!/usr/bin/perl -w use Error qw(:try); use MyErrors::SomeError; try { throw MyErrors::SomeError('throwing SomeError exception'); } catch MyErrors::SomeError with { my $err = shift; print "caught it: $err->{'-text'}\n"; };
When I run test.pl I get the following error:

Can't locate MyErrors/SomeError.pm in @INC (@INC contains: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0) at /usr/local/bin/test.pl line 4. BEGIN failed--compilation aborted at /usr/local/bin/test.pl line 4.

It seems that it can't find SomeError.pm, sorry again for the troubling but do you see something wrong here?

Hotshot

Replies are listed 'Best First'.
Re9: Error module
by dragonchild (Archbishop) on Aug 19, 2003 at 15:43 UTC
    Yeah, I see a number of things wrong.
    1. Don't code as root. In fact, don't EVER do anything as root unless you absolutely have to. It's dangerous and stupid.
    2. Don't code in /usr/local/bin. In fact, don't code in a bin directory. Ever. Code in some source directory, preferably in a directory under your home directory. I have a directory called 'perl' that I work in.

    Given that you aren't going to fix the above issues before testing this again, I would add use lib qw(/usr/local/bin); above the use MyErrors::SomeError; line. Normally, you run the perl script from the directory it's in. This allows modules that are in that directory (or subdirectories from it) to be auto-included. (This is really nice once you have a proper development environment set up.)

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      I already moved the sorces to my home exactly as you said before I posted the node (of course it screamed the same). Now it gives the same error about Error/Simple.pm.

      P.S: about the root permissions, I can't avoid that since my original script is of course a lot complex and changes Linux internal files

      Hotshot
        The problem is that your @INC array doesn't contain all the directories it needs to contain. Find the directory where Error/Simple.pm is contained, then do a use lib on it.

        Look - you're going to simply have to learn how to use packages. I can't be putting fires out for you via PM. If you want, you can hire me to do your Perl programming for you. Either /msg me here or email me at rkinyon@columbus.rr.com. I have very reasonable rates.

        P.S: If you're testing a new feature out, don't do it in your production script. Create a test script and never run those as root, unless you have to.

        ------
        We are the carpenters and bricklayers of the Information Age.

        The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://284938]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found