I want the perl script to conditionally select between two modules.
Hard coding the module name and using use works, so I know the module interface is correct. Hard coding the required module name works. The problem is when I use a variable for the module name. It should work. I've seen examples, but it does not. Help.
# This works
require Reminderst;
import Reminderst qw(@annualReminders);
print "Annual Reminders 0: $annualReminders[0]{subject}\n";
exit;
# This gets "Can't locate Reminderst in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at d:\perlscripts\reminder\reqtest.pl line 11."
$moduleName = "Reminderst";
require $moduleName;
import $moduleName qw(@annualReminders);
print "Annual Reminders 0: $annualReminders[0]{subject}\n";
exit;
# This gets no compile errors, but doesn't import arrays
$moduleName = "Reminderst.pm";
require $moduleName;
import $moduleName qw(@annualReminders);
print "Annual Reminders 0: $annualReminders[0]{subject}\n";
exit;
#
# Here is module for above (in current directory).
#
package Reminderst;
use Exporter();
@ISA=('Exporter');
# Explicitly export the following
@EXPORT=('@annualReminders');
@annualReminders=(
{
datestamp=>'080126',
recipient=>"Geo",
subject=>'Annual Reminder Test',
message=>'Annual Reminder Test.',
}
);
1
Hard coding the module name and using use works, so I know the module interface is correct. Hard coding the required module name works. The problem is when I use a variable for the module name. It should work. I've seen examples, but it does not. Help.
# This works
require Reminderst;
import Reminderst qw(@annualReminders);
print "Annual Reminders 0: $annualReminders[0]{subject}\n";
exit;
# This gets "Can't locate Reminderst in @INC (@INC contains: C:/Perl/lib C:/Perl/site/lib .) at d:\perlscripts\reminder\reqtest.pl line 11."
$moduleName = "Reminderst";
require $moduleName;
import $moduleName qw(@annualReminders);
print "Annual Reminders 0: $annualReminders[0]{subject}\n";
exit;
# This gets no compile errors, but doesn't import arrays
$moduleName = "Reminderst.pm";
require $moduleName;
import $moduleName qw(@annualReminders);
print "Annual Reminders 0: $annualReminders[0]{subject}\n";
exit;
#
# Here is module for above (in current directory).
#
package Reminderst;
use Exporter();
@ISA=('Exporter');
# Explicitly export the following
@EXPORT=('@annualReminders');
@annualReminders=(
{
datestamp=>'080126',
recipient=>"Geo",
subject=>'Annual Reminder Test',
message=>'Annual Reminder Test.',
}
);
1