Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^2: Directory Structure

by prakash1987 (Initiate)
on Aug 27, 2011 at 13:52 UTC ( #922820=note: print w/replies, xml ) Need Help??

in reply to Re: Directory Structure
in thread Directory Structure

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 and myfolder folder contains
Both the folder are in eg folder
use Data::Dumper;
use eg::myfolder::package1;
print @INC;
my $package1 = new package1();
warn "package ".Dumper($package1);
my $prnt = package1::DESTROY();
print "$prnt";
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;

return 'package2';
Error :

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

Replies are listed 'Best First'.
Re^3: Directory Structure
by armstd (Friar) on Aug 27, 2011 at 15:19 UTC

    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;


    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.


Re^3: Directory Structure
by GrandFather (Sage) on Aug 27, 2011 at 23:44 UTC

    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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://922820]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2018-05-20 22:28 GMT
Find Nodes?
    Voting Booth?