On Sun, 29 Jan 2006, Vitaly Sinitsin wrote:
> is it possible to pass the package_name as variable and how in the following 
> example:
> ${package_name::GLOBAL}   = $abc;

Sure:

    ${$package_name."::GLOBAL"} = $abc;

or

    ${"${package_name}::GLOBAL"} = $abc;
 
> And, in the same manner, is it possible and how to use variable instead of 
> package name in the:
> use package;

You'll have to use require() inside a begin block.  Instead of

    use Foo::Bar qw(some_sub);

you would have to write something like this:

    BEGIN {
        my $pkg = "Foo::Bar";
        my @import = qw(some_sub);

        (my $file = $pkg) =~ s,::,/,g;
        require "$file.pm";
        $pkg->import(@import_list);
    }

Depending on your use case you may not need to put things into a BEGIN block, 
especially if
you don't need to import symbols from the other package.

Cheers,
-Jan


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to