On Fri, 18 Mar 2005 07:46:48 -0500, zentara <[EMAIL PROTECTED]> wrote: > On Thu, 17 Mar 2005 18:57:47 +0200, [EMAIL PROTECTED] (Offer Kaye) > wrote: > > >On Thu, 17 Mar 2005 11:40:10 -0500, zentara wrote: > > > >> > > >> >The above works fine , but I do not want to fork out a new perl process > >> >every time. Is there a way I can avoid this. I would like to use do() > >> >but how do I get the out from do(); > >> > >> You might be able to use the piped form of open, but I find > >> it easier to use IPC::Open3. > >> > > > >Since the original question was "I do not want to fork out a new perl > >process", I don't see how your solution helps, as the open *will* fork > >out a new process. > > Err, the original question was: > > "The above works fine , but I do not want to fork out a new perl process > every time. " NOT "I do not want to fork a process". > > See the "every time"? > > That insinuates he desires to fork just once, like the backticks do, > but not repeatedly. > do has two serious problems in the original context. 1) The original code passes the script command line arguments; `perl $script $a $b $c` != 'eval "cat $script.pl"', and 2) the OP is clearly executing the code in a loop, and has clearly expressed concerns about re-reading the files each time. do not only reads from disk each time, but re-searches @INC each time as well. Each time through the loop it incurs nearly the overhead of loading a module, but unlike a module or eval, it won't see variable from the caller.
Your best bet is still something like this: [code] my %SCRIPTS; my %list_of_scripts = ( "user" => "file", "user2" => "file", "userAdInfinitum" => "lastfile" ) while (my ($user, $file) = each %list_of_scripts) { unless ($SCRIPTS{$file}) { open(SCRIPT, "<", $file) ; { local $/ ; # or build line at a time $SCRIPTS{$file} = <SCRIPT> ; } } local @ARGV = ( $cmdLine1, $cmdLine2, $cmdLine3 ) ; eval $SCRIPTS{$file} ; # or use s/// to load @ARGV in the stored code # depends on your feelings about local } [/code] Memory space vs. disk access is a personal issue; DB_File might be a good compromise. But there's no reason to search @INC and guarantee a reread of the file on every pass through the loop with do. HTH, --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>