If you are using require, then really you are treating C.perl as a module. It's more conventional to use a .pm extension and use use. But in either case what you are doing is somewhat like a #include in C - in a sense you are including the (compiled) source of C.perl in the execution space of A.perl. If you run B.perl as a separate process the B.perl process does not have access to the execution context of A.perl and thus does not have access to the array tucked away in C.perl.
You need to tell us something of the bigger picture and what you are trying to achieve at a higher level. You should also put together a little sample code to demonstrate what you are trying to do. Acme::ESP is currently a little flaky so it doesn't always help with this sort of question (although no-one is reporting bugs - we just expect the module's developers to know).
True laziness is hard work
| [reply] |
It will be nice if you post the code that you have done . Moreover read the Writeup formatting tips before posting
--Lakshmanan G.
The great pleasure in my life is doing what people say you cannot do.
| [reply] |
You do not seem to appreciate how processes work - if I am wrong them please forgive me, like other monks I am having difficulty in understanding the issue.
When you use system or `backticks` you will create a new process. That process effectively has a "firewall" around it preventing other processes from accessing anything inside. So if you set an array in one process it cannot normally be seen by another. To get around that there are features called IPC - InterProcess Communication. The simplest IPC mechanism is to use a pipe, which you are probably familiar with in ls|more. More complex mechanisms, like message queues and shared memory require synchronisation and locking, and you probably don't want to go there.
What I can't figure out is why you are running separate processes at all, in fact the "code" you supplied (which is basically a bunch of comments) does not create a process. As others have said, placing other subroutines in modules, then loading these modules using use or require is the normal way of doing things.
So, the question is, are these different programs which have to run, or just subroutines that can run in the same process?
Update: I missed the call to system when I looked at your "code" - hardly surprising the way you formatted it. Basically you cannot pass a Perl array back and forth between processes in a simple manner: data is not shared automagically, you have to use an IPC mechanism, a database, or a file. Better yet - don't use separate programs. | [reply] [d/l] |
The easiest way to make data generated by A.perl available to a separate process running B.perl may be to have A.perl write the data to external storage that B.perl can read. This would commonly be a database or file.
To learn how to use a database you might read some of the material in Database Programming.
To use a file, you have many options for formatting your data. You might search CPAN for serialize. In particular, you might be interested in YAML. There are also many modules that would help you if you wanted to save your data in the form of an XML file: you can search cpan for xml for options.
Another set of modules that you might find helpful are the Tie modules. Tie::Concurrent comes to mind as it appears you want concurrent access to the data. If you are certain that concurrency is not an issue then Tie::Simple or Tie::Persistent may be adequate.
Otherwise, you might consider the options presented in perlipc.
| [reply] |
I think it would help if you could include the relevant pieces of code from A, B and C so we can make some sense of your post. After reading it a dozen times I am still not sure what you are trying to do and/or how to help you. | [reply] |