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

Hello Monks


I want to use Config::Simple to read a ini file in my program
. I created lib folder in my local project directory
and downloaded Simple.pm from CPAN...I used the following code to show the Simple.pm file
use FindBin (); use lib "$FindBin::Bin"; use lib "C:\Testing\ITP"; #Simple.pm"; use Simple; print "Simple.pm => $INC{'Simple.pm'}\n"; # --- OO interface: $cfg = new Simple('app.ini'); # accessing values: $user = $cfg->param('User'); print "\n User Name $user \n";

The program prints the following output when I run

Simple.pm => C:/Testing/ITP/Simple.pm
Can't locate object method "new" via package "Simple"
(perhaps you forgot to load "Simple"?)
at readProps.pl line 18.

How to specify the Simple.pm or is it the right way...I
don't have access rights to download CPAN modules so I would
like to distribute the same with my project

Thanks in advance

Sridhar

Replies are listed 'Best First'.
Re: Specifying .pm files
by davorg (Chancellor) on Aug 17, 2006 at 10:20 UTC
    I created lib folder in my local project directory and downloaded Simple.pm from CPAN

    That sounds like you just copied the module from CPAN and didn't install it using the proper tools. It's possible to get that to work, but it's usually harder than just using the "cpan" or "ppm" command line tools. In this case, you need to create a directory called "Config" which contains Simple.pm.

    Secondly, in the code you've shown, you haven't used the Config::Simple module. You need to add use Config::Simple; to your code.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Specifying .pm files
by rodion (Chaplain) on Aug 17, 2006 at 11:34 UTC
    To add to the comments above, one thing that seems to be tripping you up (that I didn't see emphasized in the links mentioned) is the implicit correspondence between module names and directory structure. As davorg told you, the module name is "Config::Simple", not "Simple", but that also means that perl expects to find it as a file "Simple.pm" in a directory named "Config", so it's looking for "Config\Simple.pm" in its library paths.

    "C:\Testing\ITP\Config\Simple.pm" is the path I think you wanted. When you instead put it at "C:\Testing\ITP\Simple.pm", the file still has "package Config::Simple;" in it to define the module's name, which doesn't match the path.

      Hello Monks

      even after specifying the directory structure I am still getting
      compilation erros. where am missing
      Can't locate auto/Config/Simple/autosplit.ix in @INC (@INC contains: C +://Testing//ITP//Config C:/Testing/ITP c:/Perl/lib c:/Perl/site/l ib .) at c:/Perl/lib/AutoLoader.pm line 158. at C:/Testing/ITP/Config/Simple.pm line 13 Can't locate auto/Config/Simple/autosplit.ix in @INC (@INC contains: C +://Testing//ITP//Config C:/Testing/ITP c:/Perl/lib c:/Perl/site/l ib .) at c:/Perl/lib/AutoLoader.pm line 158. at C://Testing//ITP//Config/Simple.pm line 13 Simple.pm => C://Testing//ITP//Config/Simple.pm Can't locate object method "new" via package "Simple" (perhaps you for +got to load "Simple"?) at readProps.pl line 14.

        You still haven't installed it properly.

        To clarify, it looks like the module includes compiled XS code. For modules like this, you can't just copy files from CPAN into the right place. You need to install the module properly. You should still be able to use 'ppm'.

        --
        <http://dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

Re: Specifying .pm files
by Anonymous Monk on Aug 17, 2006 at 10:36 UTC
Re: Specifying .pm files
by ides (Deacon) on Aug 17, 2006 at 13:57 UTC

    You might also want to use the module properly. It should be:

    use Config::Simple;

    not just:

    use Simple;

    Frank Wiles <frank@revsys.com>
    www.revsys.com

Re: Specifying .pm files
by mantra2006 (Hermit) on Aug 17, 2006 at 13:40 UTC
    Hello Monks


    Thanks alot for the replies and everything worked..I did the following

    1. Downloaded the tar.gz(Config::Simple)
    2. perl Makefile.PL
    3. nmake test
    it created lib folder
    I copied that lib folder to my project directory and
    the program worked without any errors


    Sridhar </code>