Olivier Wirz wrote:

> Hello,
> 
> Ich would like to load dynamically a Perl class (late binding).
> 
> For example, if I start a Perl script with a command line parameter like
> --sport=SWIMMING, I would like to have something like that (after having
> saved SWIMMING via $opt_sport in variable $aSport):
> 
> my $aSport = $opt_sport;
> use Classes::$aSport;  <----- doesn't work !
> 
> Who knows a solution. Many thanks.
> 

not sure what you really trying to do but are you tring to do something 
like:

#!/usr/bin/perl -w
package Dog;

use strict;
use Exporter;
our @ISA = qw(Exporter);

sub new{
        return bless {name => $_[1]} => $_[0];
}

sub get_name{
        return $_[0]->{name};
}

1;

__END__

and then in a driver script:

#!/usr/bin/perl -w
use strict;

print "Enter class name: ";
chomp(my $class = <STDIN>);

eval<<"CODE";
require $class;
my \$obj = \$class->new("pet");
print \$obj->get_name,"\n";
CODE

print "$@\n" if($@);

__END__

runs:

Enter class name: Dog
pet

loads the Dog class at runtime and prints its name. not sure if that's what 
you want.

david

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

Reply via email to