You can pass data from an script to another in several ways:
- Using environment variables
- Using the program argument list
- Saving the data to a file on disk
- Pasing the data through STDIN/STDOUT or other shared pipes
- Using shared memory
- etc...
Regarding how to launch the script B, you can just use system.
Anyway, if you describe us the real problem you are trying to solve in detail, we would be able to give you more accurate help. | [reply] [d/l] |
Why? What is the bigger problem you are trying to solve? It is very likely that there is a simple way to achieve your overall objective that doesn't involve several scripts and endeavouring to pass data from the first to the next.
True laziness is hard work
| [reply] |
the bigger picture is that i have to run a couple of perl scripts in which Script A will call script B but in order to run script B, it needs to have the same values or input that i had input in to script a.
overall script A is a list of tests that are done separately and script B is a test where the tests are done one after the other in a combination. all i have to do is to connect it so that i just need to run one script then choose my options from then on. i cannot use subroutines for most of the script because the same variables are used everywhere and when i tried using pass by reference(\) i was getting a result but that result was not returned. so i thought just make script B and then call it from script A. but i need the hash variable from script a in script b so that script B works fine
| [reply] |
So actually the bigger picture is that you want to be able to run two sets of tests where the second set comprises combinations of the tests in the first set. A little back story that leaked through was that you had trouble implementing your first try and rather than seeking help resolving those (fundamental programming related) issues you have worked around them and been bitten by essentially the same issues in a different guise.
If you would like some real help with this problem I strongly suggest you should show us the nature of the tests you wish to perform. Testing of various sorts is something that is done often in Perl encouraged by CPAN. There is a lot of support for writing tests suites in Perl.
True laziness is hard work
| [reply] |
The bigger, bigger picture is that you obviously have basic lessons to learn about modularity. You have a lot of variables that are referred to from everywhere with very few subroutines. That is a string of red flags to any experienced programmer.
| [reply] |
If script A does something useful, then you can't do this.
My first inclination would be to move the variable from script A to module C, use it in script A, and use it in script B. Alternately you can set logic in script A saying, "Don't do anything if variable $x is set", and set it in script B before doing script A.
I'm pretty sure that if I saw the actual scripts in question I could come up with a much better solution than the two suggestions I gave you off of the top of my head. | [reply] |
Storable is ideal for this. store the hash in script A and retrieve in script B.
| [reply] [d/l] [select] |