in reply to "use" file...

First, use is a compile-time operation, so hopefully, you have some way of getting the value early enough in the process. If not, you'll have to switch to require.

Which brings me to the second point. You can't provide a variable string to use, but you can decompose it to its definition: a BEGIN block around a require and a method call:

## replace "use $string @imports" with: BEGIN { (my $filename = $string) =~ s,::,/,g; # unix/windows only require $filename; $string->import(@imports); }

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re:(merlyn) Re: "use" file...
by demerphq (Chancellor) on Feb 08, 2003 at 23:25 UTC
    The other approach is to
    BEGIN { eval "use $string \@imports; 1" or die "Failed lazy use(): $@"; }
    Er. pfaut already said this. Sorry. :-)

    Update:

    As merlyn said below. You need to be real careful that $string is completely under your control. You dont want to be reading it froma file for instance. At least not without some serious data cleaning first.

    --- demerphq
    my friends call me, usually because I'm late....