TeFloN has asked for the wisdom of the Perl Monks concerning the following question:

I want to require a script that is housed on another server anyone off the top of there head know how to do this??

ie require "whatever.domain.com ....and the script on that server"; #dunno what the format is??

hope this makes sense.

Replies are listed 'Best First'.
Re: a require statement problem
by perrin (Chancellor) on Aug 28, 2001 at 06:58 UTC
    There is nothing built into Perl that will do this. If you need it, you could implement it yourself. You could make a function that fetches the code from a specified URL and runs it. The security implications are mind-boggling though. Maybe you should think about what you're trying to do and look for an alternate approach. Maybe some kind of remote procedure call to the foreign server?
      kewl.

      Thanks for the swift response.
      I will go back to the drawing board and find a new way to do it.
Re: a require statement problem
by Corion (Patriarch) on Aug 28, 2001 at 11:13 UTC

    There is, of course, an obscure and for good reason not well used path, but you can (ab)use the use lib statement to load code from wherever you want. The interesting part of this will of course be error checking and error recovery.

    To give credit, where credit is due, I picked up this idea from one of Abigails JAPHs (sadly, Abigail is not currently with us).

    Here's Abigails JAPH :

    use lib sub {($\) = split /\./ => pop; print $"}; eval "use Just" || eval "use another" || eval "use Perl" || eval "use +Hacker";

    Now what you would need to do is to use LWP; and your use lib sub would issue an LWP::GET request to whatever URL you want. Maybe there already is a module on CPAN for this, most likely in the ACME:: namespace.

      There is a module on CPAN. It's by Abigail and it's called The::Net.

      See this node where the code is also posted.

      Error: Keyboard not attached. Press F1 to continue.

      Update: Updated link to The::Net
Re: a require statement problem
by dws (Chancellor) on Aug 28, 2001 at 08:37 UTC
    Use LWP.pm fetch the remote script into a string. (A search for LWP will reveal a multitude of examples.) Once you have the script in a string, eval it.

Re: a require statement problem
by VSarkiss (Monsignor) on Aug 28, 2001 at 07:02 UTC

    You need some mechanism external to Perl to pull this off. You can only require or do a file that is available via a regular open call as well. For example, if you had the directory where the file is located mounted locally via NFS or something like that, you could do it. But there's no built-in network traversal in Perl.