Good afternoon, my name is John, please accept my apologies for this long
post.

I am new to Perl but am enjoying the language tremendously having programmed
in other languages for many years I wish I had picked up Perl long ago. I
had thought that I understood how the 'use' pragma worked, but aparently I
do not. I am now having difficulty calling a sub in another module from a
sub in a module called from my main command line program. Is there a special
consideration when calling sub2 from sub1 when sub2 lives in a different .pm
module from sub1? My sub2 works fine when called from the command line
program but does not work (can't be seen) when called from sub1 where sub1
was called by the command line program.

Specifically I have a main program that I execute from the command line
called mprog.pl which makes use of a subroutine named 'testvolts' which
lives in a module of mine named 'Electric.pm'. The subroutine 'testvolts' in
turn calls a subroutine named 'writedate' in another module of mine named
'Other.pm'. From the mainline mprog.pl the call to writedate() works fine
giving expected results, however, when writedate is called from within
testvolts I get the error message: Undefined subroutine &Electric::writedate
called at /var/www/html/dlib/Electric.pm line 102. It seems as if the
'testvolts' sub in module 'Electric' can't _see_ or find the 'writedate' sub
that lives in module 'Other' despite the inclusion of the 'use' pragma.

It seems as if the 'use' statement is valid from within a command line
program but not valid (or is ignored) within a .pm insofar as even if I
misspell the name of a subroutine no complaint is made (whereas in a
mainline a complaint is instantly made). I can force things to work if I
fully qualify the mention of the 'writedate' sub within the 'testvolts' sub
by saying Other::writedate() but that is a pain in the butt and I thought
that 'use' was meant to solve linking problems. I imagine that I have done
something obviously stupid but I must admit I am at a loss and would
appreciate help with this.

Source snippet from mainline program mprog.pl:

#!/usr/local/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use lib("/var/www/html/dlib");
use Electric qw(testvolts);
use Other qw(writedate);
use strict;
my ($amps,$logout,$meversion,$me,$step,$startstamp,$volts);
$meversion = "0001";
$me = "mprog.pl";
$step = "1000";
$logpath = ">>../log/$me.log";
open LOGOUT, $logpath or die "Can't open $logpath because: $!\n";
$logout = *LOGOUT;
$startstamp = writedate();
print $logout "\n$me:$step:T: $startstamp\n";
($volts,$amps) = testvolts($logout,$me,$meversion)
.... (more code)


Source snippet from package Electric.pm:

package Electric;
require 5.005;
require Exporter;
@Electric::ISA=qw(Exporter);
@Electric::EXPORT_OK=qw(testvolts testamps testohms);

sub testvolts
#
# A sub to perform a voltage measurement.
#
{
 use Other ('writedate'); ## also tried use Other qw(writedate) to no avail
 use strict;
 #
 # Pick up arguments supplied by the caller.
 #
 my     ($logout,$program,$version) = @_;
 #
 # Define local variables.
 #
 my (@qresult);
 my ($count,$insert,$starttamp,$finishstamp,$db_table);
 $meversion = "0001";
 $me = "testvolts";
 $step = "1000";
 $startstamp = writedate(); ## this fails!
 $startstamp = Other::writedate() ## this works!, but I am lazy, don't want
to type Other::
 print $logout "\n$me:$step:T: $startstamp\n";
.... (other code)
}

Source snippet from package Other.pm:

package Other;
require 5.005;
require Exporter;
@Icuc::ISA=qw(Exporter);
@Icuc::EXPORT_OK=qw(ac_check blowpage writedate);

sub writedate
#
# A sub to create a customized date and time format.
#
{
 ... this routine works fine, it is just not visible to subs in the Electric
module unless they fully qualify by saying Other::writedate in which case
all is well, but I don't want to always have to use the fully qualified
name...
}
.... other subs in the 'Other' module





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to