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

Re: How to pass array as a reference from one perl file to other

by John M. Dlugosz (Monsignor)
on May 15, 2011 at 04:46 UTC ( [id://904912]=note: print w/replies, xml ) Need Help??


in reply to How to pass array as a reference from one perl file to other

I would agree with the second reply, that in this example your test-2.pl should be loaded to become part of the same program, not run as a separate process.

But maybe the example is easier than the real problem? If it's an existing program or a real mess and you can't alter it, you need some kind if Inter-Process Communication. But if you can't alter the existing program, you can't make it do that... so how is program 2 expecting the data already? Maybe you simply wanted to pass the contents of the array as individual arguments.

But you are also using the pipe-to form, so will program 2 be reading from standard input?

Without the pipe behavior, you can write:

system ("./test-2.pl", @$test);
And have test-2 see the values as the contents of @ARGV.

If you really do want to pass the data via standard input and the pipe, then your print statement would be: print FILE (join "\n",@$test); that is, write the contents of the array one value per line, which is how your existing test-2 is reading it.



Edited for correction

Replies are listed 'Best First'.
Re^2: How to pass array as a reference from one perl file to other
by Anonymous Monk on May 15, 2011 at 15:52 UTC
    I am explaning my function below.

    I am using perl tk application to extract user input from this main program and pass the arguments from the user to child program where it connect to database and perform query.

    The child program after performing the query should pass the result to the parent module.

    I need some suggestion on how to perform an two way communication between 2 perl programs where each program can chnage it control from each other saw some tips from text books on 2 way communication via use IO::Handle but its very hard to grasp its concept

Re^2: How to pass array as a reference from one perl file to other
by lidden (Curate) on May 15, 2011 at 20:06 UTC
    system ("./test-2.pl", @$test);
    And have test-2 see the values as the contents of @_.
    No, the values are in @ARGV.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://904912]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found