On Friday, August 9, 2002, at 01:37 , RAHUL SHARMA wrote:
> Hi All, > > I want to "use" a module whose filename is into some variable. > > For e.g. > > use $filename; # $filename contains the modulename that is to be > imported. think about when 'use' is dealt with by perl - it is done in the initial pass before any of your code is actually executed. as such I expect you are getting an error message of the form: File "untitled text 3"; Line 3: syntax error near "use $filename" something that I can generate with #!/usr/bin/perl -w use strict; use $filename; my $filename = "Data::Dumper"; trying to avoid the fact that use foo is the equivolent of BEGIN { require foo ;} is NOT a good idea. go back and re-read the perldoc -f require perldoc -f use since just to get past the "require" gag with say sub FunkMe { my ($mod, $var1, $var2) = @_; $mod =~ s/::/\//g; $mod .= ".pm"; require $mod; import $mod ; my $d = $base->new([$var1, $var2]); print $d->Dump; } still basically requires that you know apriori that "$mod" will in fact have the 'method' you plan to invoke.... It's a long row to hoe - but hey if you want it... ciao drieux --- #!/usr/bin/perl -w use strict; my $filename ='Data::Dumper'; my $me = do { # # the funny pre-grot for darwin offsetting. # my $preGrot = '/Network/Servers/gax/export'; my ($base , $lib); { base => $base = $preGrot . '/archive/solaris/patches', lib => $lib = "$base/lib", host_dir => "$lib/hosts", xref => "$lib/hosts/patchdiag.xref", url => { base => 'http://sunsolve.sun.com/pub-cgi/', prefix => 'patchDownload.pl?target=', suffix => '&method=h', } } }; # end Defining our world funk_Me($filename, $me, $filename); #------------------------ # sub funk_Me { my ($mod, $var1, $var2) = @_; my $base=$mod; $mod =~ s/::/\//g; $mod .= ".pm"; require $mod; #import $mod ; my $d = $base->new([$var1, $var2]); print $d->Dump; } # end of FunkMe -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]