Use is a "declaration" so you may want to "use" all of them ... then "call"
the one wanted from main ... meaning the name of the sub would need to
reflect which "class" "foo1, foo2, foo3" ...
perl -e 'print "class ?:";
$class=<>;chomp($class);
$sub="foo$class";
&$sub;
print "back from <$sub>\n";
sub foo1 {print "sub foo1\n";}
sub foo2 {print "sub foo2\n";}'
class ?:1
sub foo1
back from <foo1>
SUN1>perl -e 'print "class
?:";$class=<>;chomp($class);$sub="foo$class";^J&$s>
class ?:2
sub foo2
back from <foo2>
hope this helps ...
-----Original Message-----
From: Hakan Aksu [mailto:[EMAIL PROTECTED]]
Sent: June 09, 2001 20:26
To: [EMAIL PROTECTED]
Subject: Re: Making use of "use" dynamic ?
thanks for the response.
However my problem is not calling the variables. but calling the module.
Let says I have this directory structure :
~myapp/class1/foo.pm
~myapp/class2/foo.pm
~myapp/class3/foo.pm
and my @INC has "~myapp/"
I wan to call :
use class?::foo; #dynamic
where class? is the variable..
e.g:
$dirname = "classX";
use $dirname::foo #error!!!
use "$dirname".::foo #error!!!
fliptop wrote:
>hkn wrote:
>
>>Can someone please tell me how I can pass variables when using "use" ?
>>
>
>create a file called SomePackage.pm:
>
>package SomePackage;
>our $var = "hello world.\n";
>1;
>__END__
>
>
>and in the cgi:
>
>#!/usr/bin/perl -w
>use strict;
>use SomePackage;
>print $SomePackage::var;
>
>
>will return
>
>hello world.
>
>
>you could also do it this way:
>
>create a file called SQL.pm:
>
>package SQL;
>sub query {
> return <<QEND;
> select foo from bar
>QEND
>}
>1;
>__END__
>
>
>and in the cgi
>
>#!/usr/bin/perl -w
>use strict;
>use SQL;
>print SQL->query();
>exit();
>
>
>this will return
>
>select foo from bar
>
>hope this helps.
>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com