in reply to Directory Structure

You should post your exact error message and use code tags.

You need to add the full directory containing directory B to @INC:

Replies are listed 'Best First'.
Re^2: Directory Structure
by prakash1987 (Initiate) on Aug 27, 2011 at 13:52 UTC
    I am giving exact code and error
    I have two folders one is hello and second one is myfolder. Both the folder are parallel like A and B
    . Folder hello contains hello.pl and myfolder folder contains package1.pm
    Both the folder are in eg folder
    hello.pl
    #!/usr/local/bin/perl
    use Data::Dumper;
    use eg::myfolder::package1;
    print @INC;
    my $package1 = new package1();
    warn "package ".Dumper($package1);
    my $prnt = package1::DESTROY();
    print "$prnt";

    package1.pm
    package package1;
    sub new {
    my($class, $name) = @_; # Class name is in the first parameter
    my $self = { name => $name }; # Anonymous hash reference holds instance attributes
    bless($self, $class); # Say: $self is a $class return $self;
    }

    sub DESTROY {
    return 'package2';
    }
    1;
    Error :

    Can't locate eg/myfolder/package1.pm in @INC (@INC contains: C:/Perl/site/lib C: /Perl/lib .) at hello.pl line 3. BEGIN failed--compilation aborted at hello.pl line 3.

      Your 'package' name doesn't match your 'use', first of all.

      use eg::myfolder::package1; package package1;

      should be

      use eg::myfolder::package1; package eg::myfolder::package1;

      or

      use package1; package package1;

      In either case, you should either execute your script from within the parent directory of the first level of the package name, or have that directory in @INC (via -I, 'use lib', etc). The parent directory of "eg", or the parent directory of "package1" (myfolder), depending on the name you choose. 'print @INC' isn't helping because your script fails to compile, but Perl prints @INC helpfully in your compilation error anyway.

      Writing Modules has a similar issue, with good references to go read on this topic and other issues you'll run into fairly quickly once you get past this one.

      --Dave

      Do not tell lies. You are not giving the exact code nor the exact error. You have "sanitised" both to the point that they do not provide the information we require to provide informed help that directly addresses the problem you are having. There are a multitude of possible mistakes that could result in the type of error you describe. While we can, and do, guess which mistakes are most likely, we can't give a definitive answer if you give us inaccurate fuzzy information.

      Do you want help? If so, give us good information!

      True laziness is hard work