Link to home
Start Free TrialLog in
Avatar of adnan_m
adnan_m

asked on

calling package using variable in perl

Hi Expert.

I still new in perl. Hope that you guys can guide me with this. :-)

I try to make a perl program that automatically detect a name and use the config file to load the setting.

I'm finish with the detection program and now stuck at the config file.


I'm getting this error:
"Use of uninitialized value in concatenation (.) or string at one.pl line 13."

Thanks for helping.

Regards,
Adnan


The code as follow.

####### one.pl ############
#!/usr/bin/perl

use strict;
use warnings;


my $max_setting;
my $chassis = "car1";
my $readData = "MAXIMUM_SETTING";

$max_setting = ReadPackage($chassis, $readData);

print "$max_setting\n";


sub ReadPackage{

      my ($package, $function) = @_;
      print "package = $package\n";
      print "fucntion  = $function\n";
      my $dataRead;

      $dataRead = eval " use $package (); ${package}::$function()";

      return $dataRead;
}

#########end of one.pl #############

########## car1.pm ###############
package car1;

$MAXIMUM_SETTING = 100;
$RECOMMENDED_SETTING = 70;
$MINIMUM_SETTING = 20;

1;
############ end of car1.pm #########

ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adnan_m
adnan_m

ASKER

Thanks for your replay. I learn a lot for you. I never put the use warning and strict in module before.
I'll take note from your comment regarding to check $@ after calling eval.

The problem have been solve.

Thanks again.

Adnan