in reply to Re: making a library
in thread making a library

Hi, Tried following your suggestion but the same problem persists. Foo2->bar(); ###Cant locate object method "bar" via package Foo2.

Replies are listed 'Best First'.
Re^3: making a library
by GrandFather (Saint) on Mar 08, 2011 at 09:45 UTC

    With Foo.pm in the same directory as test.pl (assuming that is the current directory when you run test.pl) where test.pl contains:

    use strict; use warnings; use Foo; Foo->bar(); Foo::bar();

    I get:

    Hello Hello

    Using either the name space variant (Foo::bar) or the class method variant (Foo->bar) of calling bar makes no difference for this code because the "Foo" parameter passed into the class method call variant is not used.

    The important thing is that the path to Foo.pm is in @INC. To check that you could alter test.pl to:

    use Foo; print join "\n", @INC, ''; Foo->bar(); Foo::bar();

    and check that the list of paths includes the path to Foo.pm. You also need to ensure that the file name case and package case match: use Foo everywhere - not foo, FOO or some other variant, but Foo everywhere.

    True laziness is hard work
Re^3: making a library
by tospo (Hermit) on Mar 08, 2011 at 09:27 UTC
    have you changed "use Foo1" to "use Foo2" in the script that calls the subroutine? Have you changed the name of the package to Foo2 as well?
    What you are doing at the moment isn't object-oreinted code, so you should call the subroutine simply with Foo2::bar. Or just simply "bar()" because you exported "bar" from pacakge Foo2 into the local namespace of the script that uses Foo2.
      Yes sir, I did all that. I created a new module altogether called Foo2.
      Yes sir I did all that. I created a new module called Foo2. Is it coz of some problem related to strawberry?
        can you post exactly what you have at this point and where the files are if they are not in the same directory?