Gossamer Forum
Home : General : Perl Programming :

declare package from variable

Quote Reply
declare package from variable
Is it possible to declare a package name in a ".pm" file from a variable?

Ex. - file Jon.pm

Code:
my $p = "buddy::Jon";
package $p;
... rest of module...

Thanks,

- Jonathan
Quote Reply
Re: [jdgamble] declare package from variable In reply to
Hi,

Can't say I've ever tried it, but I would imagine you could. Have you tried it? =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] declare package from variable In reply to
Andy,

I'm experiementing with the notion of installing a plugin that can work on GForum, GLinks, and GCommunity...

Example, the Tables plugin.

All the includes I can just use an if statement, but it seems difficult to declare the package name...

So I would need something along the following:

Code:
if ($ENV{SCRIPT_FILENAME} ~= m/community.cgi/) {
package Plugins::Community::Jon;
}
else {
package Plugins::Jon;
}

Obviously that won't work, but I'm stipulating that it is possible somehow.

Any ideas?

Thanks,

- Jonathan
Quote Reply
Re: [jdgamble] declare package from variable In reply to
Hi,

Mmm - in that case, not sure it would work (cos I believe packages need to be declared prior). However, it can't hurt to try Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!