in reply to Re: Importing symbols into main when library is already in %INC
in thread Importing symbols into main when library is already in %INC

Ok, I paired it down a little and noticed something different this time. NETWORK::SNMP is a module I use to define OIDs and community strings. NETWORK::Discovery is a package that uses NETWORK::SNMP. I wrote and executed the two different scripts below. Why is it that if I say "use NETWORK::Discovery;" before I say "use NETWORK::SNMP", the variable $commstring is not defined in package main?
nmss_/var/scripts # cat test.pl #!/usr/bin/perl -w use NETWORK::SNMP; use NETWORK::Discovery; print "$commstring\n"; nmss_/var/scripts # ./test.pl not_real_community_string nmss_/var/scripts # cat test2.pl #!/usr/bin/perl -w use NETWORK::Discovery; use NETWORK::SNMP; print "$commstring\n"; nmss_/var/scripts # ./test2.pl Name "main::commstring" used only once: possible typo at ./test2.pl li +ne 6. Use of uninitialized value in concatenation (.) at ./test2.pl line 6.
  • Comment on Re: Re: Importing symbols into main when library is already in %INC
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Importing symbols into main when library is already in %INC
by merlyn (Sage) on May 16, 2001 at 22:30 UTC
      I am using the standard importer, I think (I never overloaded any import function). At the beginning of NETWORK::SNMP, I have the following code (periods represent omitted code):
      require Exporter; @EXPORT=qw(@chassistypes $commstring $sysname $syscontact $syslocation + $ipadentaddr $cdpdevicecacheport $ipadentnetmask $cdpcacheplatform $cdpcach +edeviceport $chassisid $chassistype $sysdesc $romid); ........ $commstring=`/usr/bin/cat /var/scripts/.data/commstring`; chomp $commstring; ........ 1;
      The following code appears in NETWORK::Discovery:
      package NETWORK::Discovery; use NETWORK::SNMP; use Net::SNMP; use Net::Ping; sub new { ... } sub discover_pvp { ... } sub getnext_device { .... } sub getnext_nonsnmp { ... } 1;