If one.pl is not in a CGI environment
If your one.pl is a shell script, you can set @ARGV before the call to require. This abuses CGI's mode to work with command line arguments. The arg needs to be the param name equals the value.
{
my $number = 5;
local @ARGV = ( "number=$number" );
require "two.pl";
}
The key=value format is important. The local keyword makes sure that @ARGV is only set inside the block, making sure other possible arguments to your script are not permanently lost, but rather invisible to two.pl.
If one.pl is in a CGI environment
- If the param is already there, you don't have to do anything.
- Else, see above.
Note that for both of these you can only ever require a script once. That's the idea of require. Perl keeps track of what it's loaded already (in %INC). If you are in an environment like mod_perl, or a modern Perl application that runs persistently, you should use do "two.pl" instead, which will execute it every time. But then that might break other things if two.pl is not designed to be ran multiple times in the same process.
Your best bet is to refactor the code inside two.pl into a module, and use that in both scripts.
$numberalready a CGI param, or a different value?requirefor .pl files. You should be usingdo.two.plactually does. There is a pitfall with therequiresolution and it is the wrong choice. Persisting with it may suit your purposes, but you are condemning others to deal with hard-to-find bugs.one.plandtwo.plcontain so that we can better understand what you're trying to do. If you can reduce it to just a few lines of code that we can run ourselves then that would be excellent!