SPUG: Modules - more than one object in file?

Brian Ingerson briani at activestate.com
Wed Oct 11 13:36:01 CDT 2000


Todd Wells wrote:
> 
> When I run your code it works, but this code is in the same file.
> 
> If I save packages A and B in A.pm (and append 1;), and then create test1.pl
> that has this:
> 
> # test1.pl
> use A;
> $b = B->new;
> $b->foo;
> 
> Now when I run test1.pl, I get this:
> 
> ~/myperl$ perl test1.pl
> Can't locate A.pm in @INC (@INC contains: d:/Perl/lib d:/Perl/site/lib .) at
> tes
> t1.pl line 1.
> BEGIN failed--compilation aborted at test1.pl line 1.
> ~/myperl$

Where did you put A.pm. It should be in the same dir as test1.pl, and
you need to run it from there as well.

'perl test1.pl' works for me with these 2 files:

--------------8<----------------
# A.pm
package A;
sub foo { print "It worked\n" }

package B;
@ISA = qw ( A );
sub new { bless [], shift }

1;
--------------8<----------------
# test1.pl
use A;
$b = B->new;
$b->foo;
--------------8<----------------

Brian

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list