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

to my clever monks: How can I call a file, say proxy.pl in a subroutine called sub list_sorts(...)? Thanks, PMONK

Replies are listed 'Best First'.
Re: Calling files in sub
by blackjudas (Pilgrim) on Aug 27, 2001 at 23:28 UTC
    Certainly depends on what you'd like the file to accomplish. There are 3 different methods you can apply here, the first is:

    do "proxy.pl";

    Which will use lexically scoped variables, meaning that if you have variables in your subroutine which are also declared in your included file you can use code inside your file to modify/work with variables in your subroutine.

    The other method is:

    require "proxy.pl";

    Which cannot use the variables inside your subroutine, also it will error out if it cannot find the file requested which is something that do won't.

    The other option is to create a module which is my preferred method, this creates a new namespace and will allow for greater flexibility such as non-confilicting variable names as well as the ability to reuse your code at a later date ... well that's just my opinion.
Re: Calling files in sub
by mischief (Hermit) on Aug 28, 2001 at 18:23 UTC

    Just in case: I'm not entirely sure of what you're asking, but if you want to execute an external file (program, script or whatever), use system().

    I think blackjudas has probably already answered this, though.