CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [FishMonger] In a perl-script trying to execute another perl-script that SETS SOME VARIABLES for caller script: Edit Log



alex5161
Novice

Mar 1, 2018, 12:49 PM


Views: 7179
Re: [FishMonger] In a perl-script trying to execute another perl-script that SETS SOME VARIABLES for caller script

 Thank, BillKSmith and FishMonger for the pretty the same answer with advise to use a file to communicate processes.
My point is in position: if a script is in Perl, it is sounds foolishly to have another 'piece of the Perl-code' be a separate process, unless it is decided!
After all, the second script could be just copied into the first one.
That is another 'bad way' to resolve it, besides a file.
Up to now I have covered all functionality of the second script in the function 'main_scr2()' and used 'requre()' in first fcript to load it to first-script area and run the 'main_scr2()' with needed parameters, having that function setting needed variables.
So, like that:
- In script 1:

Code
....  
require 'script2.pl';
eval "main_scr2 ('parm-1', 'parm-2')";
print @set_var;
....

- In script 2:

Code
my $itself = ($0 =~ __FILE__);  # set indication of current use 
if ($itself) {
... # all the process initialization steps
main_scr2();
}
else { 1; } # for calling from a script by 'require(): need TRUE returned

sub main_scr2
{
@input = @_ ? @_ : @ARGV;
.... # all script functionality
our @set_var = ($val, $val1,...);
exit 0 if $itself;
}

Not elegant, but better than a file in any way (including the 'Storable')

Anyway, thanks for participation!

FishMonger
BTW, I am not guessing what the 'an XY problem' is. Not familliar with such idiom, if it is...


(This post was edited by alex5161 on Mar 1, 2018, 12:55 PM)


Edit Log:
Post edited by alex5161 (Novice) on Mar 1, 2018, 12:52 PM
Post edited by alex5161 (Novice) on Mar 1, 2018, 12:55 PM
Post edited by alex5161 (Novice) on Mar 1, 2018, 12:55 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives