http://www.perlmonks.org?node_id=879447

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

Namaste Monks! This is somewhat like an extension to a question that I had posted earlier Array comparison using perl. In my previous question I'd used arrays

my @arr1 = ('1','2','3','4','5','6','7','8','9'); my @arr2 = ('1','4','5','9','7');
and sought help to run a comparison between the two. But now my requirement has changed in a way that @arr1 is in one script say script1.pl and @arr2 in another script say script2.pl, both scripts found in the same directory. I need to run the array comparison procedure (which was the solution to my former question) in script2.pl and for this to occur @arr1 from script1.pl must be called into script2.pl. It must be noted that the arrays do not contain predefined values as shown. Please help me out with this wise Monks! Thanks!

Replies are listed 'Best First'.
Re: Passing values between different scripts
by Corion (Patriarch) on Dec 28, 2010 at 15:38 UTC

    Write the array into a file, read it in the second script and output the comparison there.

    Or convert the second script to a module and use it in the first script.

      Thank you Corion. Two working options. I'm gonna try out and learn both. Thanks a lot. I'm very happy :-)

Re: Passing values between different scripts
by fisher (Priest) on Dec 28, 2010 at 15:42 UTC
    maybe using modules will save your time and nerves? You can put your arrays in module and use it from your two scripts. See Simple Module Tutorial.

      Looks like you've read right through me! Thanks a lot fisher :-)

Re: Passing values between different scripts
by JavaFan (Canon) on Dec 28, 2010 at 16:05 UTC
    Is script1.pl calling script2.pl? If not, are both programs running at the same time? If not, does your question make any sense? If one script is calling the other, can't you just pass the array as parameters? Or else, use shared memory/a file/a database/a pipe/a socket to pass information back and forth. See man perlipc.
Re: Passing values between different scripts
by jethro (Monsignor) on Dec 28, 2010 at 15:40 UTC

    You could read in your script1.pl into a string and use the eval function to execute it. But why would you want to do that? Is this school homework you are doing?

    The sensible thing would be to make script1.pl into a module and use it just like a library from script2.pl

      Thank you jethro!