Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Passing values between different scripts

by ajguitarmaniac (Sexton)
on Dec 28, 2010 at 15:30 UTC ( #879447=perlquestion: print w/ replies, xml ) Need Help??
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!

Comment on Passing values between different scripts
Select or Download Code
Re: Passing values between different scripts
by Corion (Pope) 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 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!

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://879447]
Approved by herveus
Front-paged by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2014-10-01 22:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (40 votes), past polls