Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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 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.


Comment on Re^2: Directory Structure
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;

    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

Re^3: Directory Structure
by GrandFather (Cardinal) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-09-24 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (243 votes), past polls